diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2017-05-02 13:18:26 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2017-05-02 13:18:26 +0200 |
commit | 4247aa319ac6e17b7ef7a76d61bac32c872575e3 (patch) | |
tree | 9f16b2c31c272cee658ab9f0b9906e3f4633951e /kamon-core/src/main/scala/kamon/metric/EntityRecorder.scala | |
parent | f24c1a7a4b96dcfb2609c6f512f34dd6d54de439 (diff) | |
download | Kamon-4247aa319ac6e17b7ef7a76d61bac32c872575e3.tar.gz Kamon-4247aa319ac6e17b7ef7a76d61bac32c872575e3.tar.bz2 Kamon-4247aa319ac6e17b7ef7a76d61bac32c872575e3.zip |
wip: playing with akka-less implementation of subscriptions
Diffstat (limited to 'kamon-core/src/main/scala/kamon/metric/EntityRecorder.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/metric/EntityRecorder.scala | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/kamon-core/src/main/scala/kamon/metric/EntityRecorder.scala b/kamon-core/src/main/scala/kamon/metric/EntityRecorder.scala index a94881d2..8ce37082 100644 --- a/kamon-core/src/main/scala/kamon/metric/EntityRecorder.scala +++ b/kamon-core/src/main/scala/kamon/metric/EntityRecorder.scala @@ -5,6 +5,8 @@ import java.time.Duration import kamon.metric.instrument._ import kamon.util.MeasurementUnit +import scala.collection.concurrent.TrieMap + trait EntityRecorder { def histogram(name: String): Histogram def histogram(name: String, measurementUnit: MeasurementUnit, dynamicRange: DynamicRange): Histogram @@ -13,11 +15,55 @@ trait EntityRecorder { def minMaxCounter(name: String, measurementUnit: MeasurementUnit, dynamicRange: DynamicRange, sampleFrequency: Duration): MinMaxCounter def gauge(name: String): Gauge + def gauge(name: String, measurementUnit: MeasurementUnit): Gauge def counter(name: String): Counter + def counter(name: String, measurementUnit: MeasurementUnit): Counter +} + +trait EntitySnapshotProducer { + def snapshot(): EntitySnapshot } -class EntityRecorderImpl { + +class DefaultEntityRecorder(entity: Entity, instrumentFactory: InstrumentFactory) extends EntityRecorder with EntitySnapshotProducer { + private val histograms = TrieMap.empty[String, Histogram with DistributionSnapshotInstrument] + private val minMaxCounters = TrieMap.empty[String, MinMaxCounter with DistributionSnapshotInstrument] + private val counters = TrieMap.empty[String, Counter with SingleValueSnapshotInstrument] + private val gauges = TrieMap.empty[String, Gauge with SingleValueSnapshotInstrument] + + def histogram(name: String): Histogram = + histograms.atomicGetOrElseUpdate(name, instrumentFactory.buildHistogram(entity, name)) + + def histogram(name: String, measurementUnit: MeasurementUnit, dynamicRange: DynamicRange): Histogram = + histograms.atomicGetOrElseUpdate(name, instrumentFactory.buildHistogram(entity, name, dynamicRange, measurementUnit)) + + def minMaxCounter(name: String): MinMaxCounter = + minMaxCounters.atomicGetOrElseUpdate(name, instrumentFactory.buildMinMaxCounter(entity, name)) + + def minMaxCounter(name: String, measurementUnit: MeasurementUnit, dynamicRange: DynamicRange, sampleFrequency: Duration): MinMaxCounter = + minMaxCounters.atomicGetOrElseUpdate(name, instrumentFactory.buildMinMaxCounter(entity, name, dynamicRange, sampleFrequency, measurementUnit)) + + def gauge(name: String): Gauge = + gauges.atomicGetOrElseUpdate(name, instrumentFactory.buildGauge(entity, name)) + + def gauge(name: String, measurementUnit: MeasurementUnit): Gauge = + gauges.atomicGetOrElseUpdate(name, instrumentFactory.buildGauge(entity, name, measurementUnit)) + + def counter(name: String): Counter = + counters.atomicGetOrElseUpdate(name, instrumentFactory.buildCounter(entity, name)) + + def counter(name: String, measurementUnit: MeasurementUnit): Counter = + counters.atomicGetOrElseUpdate(name, instrumentFactory.buildCounter(entity, name, measurementUnit)) + + def snapshot(): EntitySnapshot = + new EntitySnapshot( + entity, + histograms = histograms.values.map(_.snapshot()).toSeq, + minMaxCounters = minMaxCounters.values.map(_.snapshot()).toSeq, + gauges = gauges.values.map(_.snapshot()).toSeq, + counters = counters.values.map(_.snapshot()).toSeq + ) }
\ No newline at end of file |