aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/scala/kamon/metric/instrument
diff options
context:
space:
mode:
Diffstat (limited to 'kamon-core/src/main/scala/kamon/metric/instrument')
-rw-r--r--kamon-core/src/main/scala/kamon/metric/instrument/Counter.scala8
-rw-r--r--kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala8
-rw-r--r--kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala13
-rw-r--r--kamon-core/src/main/scala/kamon/metric/instrument/InstrumentFactory.scala78
-rw-r--r--kamon-core/src/main/scala/kamon/metric/instrument/InstrumentSnapshot.scala11
-rw-r--r--kamon-core/src/main/scala/kamon/metric/instrument/MinMaxCounter.scala5
6 files changed, 56 insertions, 67 deletions
diff --git a/kamon-core/src/main/scala/kamon/metric/instrument/Counter.scala b/kamon-core/src/main/scala/kamon/metric/instrument/Counter.scala
index 10b9c3a6..f18e771c 100644
--- a/kamon-core/src/main/scala/kamon/metric/instrument/Counter.scala
+++ b/kamon-core/src/main/scala/kamon/metric/instrument/Counter.scala
@@ -14,8 +14,8 @@ trait Counter {
def increment(times: Long): Unit
}
-class LongAdderCounter(entity: Entity, name: String, val measurementUnit: MeasurementUnit)
- extends Counter with SingleValueSnapshotInstrument with StrictLogging {
+class LongAdderCounter(name: String, tags: Map[String, String], val measurementUnit: MeasurementUnit)
+ extends SnapshotableCounter with StrictLogging {
private val adder = new LongAdder()
@@ -26,9 +26,9 @@ class LongAdderCounter(entity: Entity, name: String, val measurementUnit: Measur
if (times >= 0)
adder.add(times)
else
- logger.warn(s"Ignored attempt to decrement counter [$name] on entity [$entity]")
+ logger.warn(s"Ignored attempt to decrement counter [$name]")
}
def snapshot(): SingleValueSnapshot =
- SingleValueSnapshot(name, measurementUnit, adder.sumThenReset())
+ SingleValueSnapshot(name, tags, measurementUnit, adder.sumThenReset())
}
diff --git a/kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala b/kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala
index 5263d258..acbff912 100644
--- a/kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala
+++ b/kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala
@@ -1,8 +1,6 @@
package kamon.metric.instrument
import java.util.concurrent.atomic.AtomicLong
-
-import kamon.metric.Entity
import kamon.util.MeasurementUnit
trait Gauge {
@@ -16,8 +14,8 @@ trait Gauge {
}
-class AtomicLongGauge(entity: Entity, name: String, val measurementUnit: MeasurementUnit)
- extends Gauge with SingleValueSnapshotInstrument {
+class AtomicLongGauge(name: String, tags: Map[String, String], val measurementUnit: MeasurementUnit)
+ extends SnapshotableGauge {
private val currentValue = new AtomicLong(0L)
@@ -37,5 +35,5 @@ class AtomicLongGauge(entity: Entity, name: String, val measurementUnit: Measure
currentValue.set(value)
def snapshot(): SingleValueSnapshot =
- SingleValueSnapshot(name, measurementUnit, currentValue.get())
+ SingleValueSnapshot(name, tags, measurementUnit, currentValue.get())
}
diff --git a/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala b/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala
index 76d4ab65..29fe8c69 100644
--- a/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala
+++ b/kamon-core/src/main/scala/kamon/metric/instrument/Histogram.scala
@@ -1,9 +1,10 @@
-package kamon.metric.instrument
+package kamon
+package metric
+package instrument
import java.nio.ByteBuffer
import com.typesafe.scalalogging.StrictLogging
-import kamon.metric.Entity
import kamon.util.MeasurementUnit
import org.HdrHistogram.{AtomicHistogramExtension, ZigZag}
@@ -16,8 +17,8 @@ trait Histogram {
}
-class HdrHistogram(entity: Entity, name: String, val measurementUnit: MeasurementUnit, val dynamicRange: DynamicRange)
- extends AtomicHistogramExtension(dynamicRange) with Histogram with DistributionSnapshotInstrument with StrictLogging {
+class HdrHistogram(name: String, tags: Map[String, String], val measurementUnit: MeasurementUnit, val dynamicRange: DynamicRange)
+ extends AtomicHistogramExtension(dynamicRange) with SnapshotableHistogram with StrictLogging {
def record(value: Long): Unit =
tryRecord(value, 1)
@@ -30,7 +31,7 @@ class HdrHistogram(entity: Entity, name: String, val measurementUnit: Measuremen
recordValueWithCount(value, count)
} catch {
case anyException: Throwable ⇒
- logger.warn(s"Failed to store value [$value] in histogram [$name] of entity [$entity]. You might need to change " +
+ logger.warn(s"Failed to store value [$value] in histogram [$name]. You might need to change " +
"your dynamic range configuration for this instrument.", anyException)
}
}
@@ -81,7 +82,7 @@ class HdrHistogram(entity: Entity, name: String, val measurementUnit: Measuremen
val distribution = new ZigZagCountsDistribution(totalCount, minIndex, maxIndex, ByteBuffer.wrap(zigZagCounts),
protectedUnitMagnitude(), protectedSubBucketHalfCount(), protectedSubBucketHalfCountMagnitude())
- DistributionSnapshot(name, measurementUnit, dynamicRange, distribution)
+ DistributionSnapshot(name, tags, measurementUnit, dynamicRange, distribution)
}
private class ZigZagCountsDistribution(val count: Long, minIndex: Int, maxIndex: Int, zigZagCounts: ByteBuffer,
diff --git a/kamon-core/src/main/scala/kamon/metric/instrument/InstrumentFactory.scala b/kamon-core/src/main/scala/kamon/metric/instrument/InstrumentFactory.scala
index 33a34bdf..0e0536c6 100644
--- a/kamon-core/src/main/scala/kamon/metric/instrument/InstrumentFactory.scala
+++ b/kamon-core/src/main/scala/kamon/metric/instrument/InstrumentFactory.scala
@@ -9,49 +9,36 @@ import kamon.metric.instrument.InstrumentFactory.CustomInstrumentSettings
import kamon.util.MeasurementUnit
-private[kamon] class InstrumentFactory private (
- defaultHistogramDynamicRange: DynamicRange,
- defaultMMCounterDynamicRange: DynamicRange,
- defaultMMCounterSampleRate: Duration,
- customSettings: Map[(String, String), CustomInstrumentSettings]) {
+private[kamon] class InstrumentFactory private (defaultHistogramDynamicRange: DynamicRange, defaultMMCounterDynamicRange: DynamicRange,
+ defaultMMCounterSampleInterval: Duration, customSettings: Map[String, CustomInstrumentSettings]) {
- def buildHistogram(entity: Entity, name: String, dynamicRange: DynamicRange = defaultHistogramDynamicRange,
- measurementUnit: MeasurementUnit = MeasurementUnit.none): Histogram with DistributionSnapshotInstrument = {
+ println("DEFAULT: " + defaultHistogramDynamicRange)
- new HdrHistogram(
- entity,
- name,
- measurementUnit,
- instrumentDynamicRange(entity, name, dynamicRange)
- )
- }
+ def buildHistogram(dynamicRange: Option[DynamicRange])(name: String, tags: Map[String, String], unit: MeasurementUnit): SnapshotableHistogram =
+ new HdrHistogram(name, tags, unit, instrumentDynamicRange(name, dynamicRange.getOrElse(defaultHistogramDynamicRange)))
- def buildMinMaxCounter(entity: Entity, name: String, dynamicRange: DynamicRange = defaultMMCounterDynamicRange,
- sampleInterval: Duration = defaultMMCounterSampleRate, measurementUnit: MeasurementUnit = MeasurementUnit.none): MinMaxCounter with DistributionSnapshotInstrument = {
-
- val underlyingHistogram = buildHistogram(entity, name, dynamicRange, measurementUnit)
+ def buildMinMaxCounter(dynamicRange: Option[DynamicRange], sampleInterval: Option[Duration])
+ (name: String, tags: Map[String, String], unit: MeasurementUnit): SnapshotableMinMaxCounter =
new PaddedMinMaxCounter(
- entity,
name,
- underlyingHistogram,
- instrumentSampleInterval(entity, name, sampleInterval)
- )
- }
+ tags,
+ buildHistogram(dynamicRange.orElse(Some(defaultMMCounterDynamicRange)))(name, tags, unit),
+ instrumentSampleInterval(name, sampleInterval.getOrElse(defaultMMCounterSampleInterval)) )
- def buildGauge(entity: Entity, name: String, measurementUnit: MeasurementUnit = MeasurementUnit.none): Gauge with SingleValueSnapshotInstrument =
- new AtomicLongGauge(entity, name, measurementUnit)
+ def buildGauge(name: String, tags: Map[String, String], unit: MeasurementUnit): SnapshotableGauge =
+ new AtomicLongGauge(name, tags, unit)
- def buildCounter(entity: Entity, name: String, measurementUnit: MeasurementUnit = MeasurementUnit.none): Counter with SingleValueSnapshotInstrument =
- new LongAdderCounter(entity, name, measurementUnit)
+ def buildCounter(name: String, tags: Map[String, String], unit: MeasurementUnit): SnapshotableCounter =
+ new LongAdderCounter(name, tags, unit)
- private def instrumentDynamicRange(entity: Entity, instrumentName: String, dynamicRange: DynamicRange): DynamicRange =
- customSettings.get((entity.category, instrumentName)).fold(dynamicRange) { cs =>
+ private def instrumentDynamicRange(instrumentName: String, dynamicRange: DynamicRange): DynamicRange =
+ customSettings.get(instrumentName).fold(dynamicRange) { cs =>
overrideDynamicRange(dynamicRange, cs)
}
- private def instrumentSampleInterval(entity: Entity, instrumentName: String, sampleInterval: Duration): Duration =
- customSettings.get((entity.category, instrumentName)).fold(sampleInterval) { cs =>
+ private def instrumentSampleInterval(instrumentName: String, sampleInterval: Duration): Duration =
+ customSettings.get(instrumentName).fold(sampleInterval) { cs =>
cs.sampleInterval.getOrElse(sampleInterval)
}
@@ -73,21 +60,26 @@ object InstrumentFactory {
val customSettings = factoryConfig.getConfig("custom-settings")
.configurations
- .filter(nonEmptyCategories)
- .flatMap(buildCustomInstrumentSettings)
+ .filter(nonEmptySection)
+ .map(readCustomInstrumentSettings)
new InstrumentFactory(histogramDynamicRange, mmCounterDynamicRange, mmCounterSampleInterval, customSettings)
}
- private def nonEmptyCategories(entry: (String, Config)): Boolean = entry match {
+ private def nonEmptySection(entry: (String, Config)): Boolean = entry match {
case (_, config) => config.firstLevelKeys.nonEmpty
}
- private def buildCustomInstrumentSettings(entry: (String, Config)): Map[(String, String), CustomInstrumentSettings] = {
- val (category, categoryConfig) = entry
- categoryConfig.configurations.map {
- case (instrumentName, instrumentConfig) => (category, instrumentName) -> readCustomSettings(instrumentConfig)
- }
+ private def readCustomInstrumentSettings(entry: (String, Config)): (String, CustomInstrumentSettings) = {
+ val (metricName, metricConfig) = entry
+ val customSettings = CustomInstrumentSettings(
+ if (metricConfig.hasPath("lowest-discernible-value")) Some(metricConfig.getLong("lowest-discernible-value")) else None,
+ if (metricConfig.hasPath("highest-trackable-value")) Some(metricConfig.getLong("highest-trackable-value")) else None,
+ if (metricConfig.hasPath("significant-value-digits")) Some(metricConfig.getInt("significant-value-digits")) else None,
+ if (metricConfig.hasPath("sample-interval")) Some(metricConfig.getDuration("sample-interval")) else None
+ )
+
+ (metricName -> customSettings)
}
private def readDynamicRange(config: Config): DynamicRange =
@@ -103,12 +95,4 @@ object InstrumentFactory {
significantValueDigits: Option[Int],
sampleInterval: Option[Duration]
)
-
- private def readCustomSettings(config: Config): CustomInstrumentSettings =
- CustomInstrumentSettings(
- if (config.hasPath("lowest-discernible-value")) Some(config.getLong("lowest-discernible-value")) else None,
- if (config.hasPath("highest-trackable-value")) Some(config.getLong("highest-trackable-value")) else None,
- if (config.hasPath("significant-value-digits")) Some(config.getInt("significant-value-digits")) else None,
- if (config.hasPath("sample-interval")) Some(config.getDuration("sample-interval")) else None
- )
} \ No newline at end of file
diff --git a/kamon-core/src/main/scala/kamon/metric/instrument/InstrumentSnapshot.scala b/kamon-core/src/main/scala/kamon/metric/instrument/InstrumentSnapshot.scala
index ffb00080..1364c2d8 100644
--- a/kamon-core/src/main/scala/kamon/metric/instrument/InstrumentSnapshot.scala
+++ b/kamon-core/src/main/scala/kamon/metric/instrument/InstrumentSnapshot.scala
@@ -6,13 +6,14 @@ import kamon.util.MeasurementUnit
* Snapshot for instruments that internally track a single value. Meant to be used for counters and gauges.
*
*/
-case class SingleValueSnapshot(name: String, measurementUnit: MeasurementUnit, value: Long)
+case class SingleValueSnapshot(name: String, tags: Map[String, String], measurementUnit: MeasurementUnit, value: Long)
/**
* Snapshot for instruments that internally the distribution of values in a defined dynamic range. Meant to be used
* with histograms and min max counters.
*/
-case class DistributionSnapshot(name: String, measurementUnit: MeasurementUnit, dynamicRange: DynamicRange, distribution: Distribution)
+case class DistributionSnapshot(name: String, tags: Map[String, String], measurementUnit: MeasurementUnit,
+ dynamicRange: DynamicRange, distribution: Distribution)
trait Distribution {
@@ -48,3 +49,9 @@ trait DistributionSnapshotInstrument {
trait SingleValueSnapshotInstrument {
private[kamon] def snapshot(): SingleValueSnapshot
}
+
+trait SnapshotableHistogram extends Histogram with DistributionSnapshotInstrument
+trait SnapshotableMinMaxCounter extends MinMaxCounter with DistributionSnapshotInstrument
+trait SnapshotableCounter extends Counter with SingleValueSnapshotInstrument
+trait SnapshotableGauge extends Gauge with SingleValueSnapshotInstrument
+
diff --git a/kamon-core/src/main/scala/kamon/metric/instrument/MinMaxCounter.scala b/kamon-core/src/main/scala/kamon/metric/instrument/MinMaxCounter.scala
index cddd8ed9..70094b7b 100644
--- a/kamon-core/src/main/scala/kamon/metric/instrument/MinMaxCounter.scala
+++ b/kamon-core/src/main/scala/kamon/metric/instrument/MinMaxCounter.scala
@@ -5,7 +5,6 @@ import java.time.Duration
import java.util.concurrent.atomic.{AtomicLong, AtomicReference}
import kamon.jsr166.LongMaxUpdater
-import kamon.metric.Entity
import kamon.util.MeasurementUnit
trait MinMaxCounter {
@@ -21,8 +20,8 @@ trait MinMaxCounter {
}
-class PaddedMinMaxCounter(entity: Entity, name: String, underlyingHistogram: Histogram with DistributionSnapshotInstrument,
- val sampleInterval: Duration) extends MinMaxCounter with DistributionSnapshotInstrument {
+class PaddedMinMaxCounter(name: String, tags: Map[String, String], underlyingHistogram: Histogram with DistributionSnapshotInstrument,
+ val sampleInterval: Duration) extends SnapshotableMinMaxCounter {
private val min = new LongMaxUpdater(0L)
private val max = new LongMaxUpdater(0L)