diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2015-04-05 17:02:18 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2015-04-05 19:59:04 +0200 |
commit | 0746f0002b2e1d563d837f954b367ae063546ca1 (patch) | |
tree | ed7f0a74ed89dae008f79e479c2d788c92f942f9 /kamon-core/src/main | |
parent | 5456e7ca8f215b2a3a5bdbd3177a6ae61f268eef (diff) | |
download | Kamon-0746f0002b2e1d563d837f954b367ae063546ca1.tar.gz Kamon-0746f0002b2e1d563d837f954b367ae063546ca1.tar.bz2 Kamon-0746f0002b2e1d563d837f954b367ae063546ca1.zip |
= core: minor cleanup of metric keys and units of measurements.
Diffstat (limited to 'kamon-core/src/main')
4 files changed, 40 insertions, 42 deletions
diff --git a/kamon-core/src/main/scala/kamon/metric/MetricKey.scala b/kamon-core/src/main/scala/kamon/metric/MetricKey.scala index 2c710a19..0d4e0163 100644 --- a/kamon-core/src/main/scala/kamon/metric/MetricKey.scala +++ b/kamon-core/src/main/scala/kamon/metric/MetricKey.scala @@ -16,42 +16,32 @@ package kamon.metric -import kamon.metric.instrument.{ InstrumentTypes, InstrumentType, UnitOfMeasurement } +import kamon.metric.instrument.UnitOfMeasurement /** - * MetricKeys are used to identify a given metric in entity recorders and snapshots. MetricKeys can be used to encode - * additional metadata for a metric being recorded, as well as the unit of measurement of the data being recorder. + * MetricKeys are used to identify a given metric in entity recorders and snapshots. */ sealed trait MetricKey { def name: String def unitOfMeasurement: UnitOfMeasurement - def instrumentType: InstrumentType } /** * MetricKey for all Histogram-based metrics. */ -private[kamon] case class HistogramKey(name: String, unitOfMeasurement: UnitOfMeasurement) extends MetricKey { - val instrumentType = InstrumentTypes.Histogram -} +private[kamon] case class HistogramKey(name: String, unitOfMeasurement: UnitOfMeasurement) extends MetricKey /** * MetricKey for all MinMaxCounter-based metrics. */ -case class MinMaxCounterKey(name: String, unitOfMeasurement: UnitOfMeasurement) extends MetricKey { - val instrumentType = InstrumentTypes.MinMaxCounter -} +private[kamon] case class MinMaxCounterKey(name: String, unitOfMeasurement: UnitOfMeasurement) extends MetricKey /** * MetricKey for all Gauge-based metrics. */ -case class GaugeKey(name: String, unitOfMeasurement: UnitOfMeasurement) extends MetricKey { - val instrumentType = InstrumentTypes.Gauge -} +private[kamon] case class GaugeKey(name: String, unitOfMeasurement: UnitOfMeasurement) extends MetricKey /** * MetricKey for all Counter-based metrics. */ -case class CounterKey(name: String, unitOfMeasurement: UnitOfMeasurement) extends MetricKey { - val instrumentType = InstrumentTypes.Counter -} +private[kamon] case class CounterKey(name: String, unitOfMeasurement: UnitOfMeasurement) extends MetricKey diff --git a/kamon-core/src/main/scala/kamon/metric/Metrics.scala b/kamon-core/src/main/scala/kamon/metric/Metrics.scala index 05f333ab..11166127 100644 --- a/kamon-core/src/main/scala/kamon/metric/Metrics.scala +++ b/kamon-core/src/main/scala/kamon/metric/Metrics.scala @@ -245,7 +245,7 @@ private[kamon] class MetricsImpl(config: Config) extends Metrics { def registerHistogram(name: String, tags: Map[String, String], unitOfMeasurement: Option[UnitOfMeasurement], dynamicRange: Option[DynamicRange]): Histogram = { - val histogramEntity = Entity(name, "histogram", tags) + val histogramEntity = Entity(name, SingleInstrumentEntityRecorder.Histogram, tags) val recorder = _trackedEntities.atomicGetOrElseUpdate(histogramEntity, { val factory = instrumentFactory(histogramEntity.category) HistogramRecorder(HistogramKey(histogramEntity.category, unitOfMeasurement.getOrElse(UnitOfMeasurement.Unknown)), @@ -256,12 +256,12 @@ private[kamon] class MetricsImpl(config: Config) extends Metrics { } def removeHistogram(name: String, tags: Map[String, String]): Boolean = - _trackedEntities.remove(Entity(name, "histogram", tags)).isDefined + _trackedEntities.remove(Entity(name, SingleInstrumentEntityRecorder.Histogram, tags)).isDefined def registerMinMaxCounter(name: String, tags: Map[String, String], unitOfMeasurement: Option[UnitOfMeasurement], dynamicRange: Option[DynamicRange], refreshInterval: Option[FiniteDuration]): MinMaxCounter = { - val minMaxCounterEntity = Entity(name, "min-max-counter", tags) + val minMaxCounterEntity = Entity(name, SingleInstrumentEntityRecorder.MinMaxCounter, tags) val recorder = _trackedEntities.atomicGetOrElseUpdate(minMaxCounterEntity, { val factory = instrumentFactory(minMaxCounterEntity.category) MinMaxCounterRecorder(MinMaxCounterKey(minMaxCounterEntity.category, unitOfMeasurement.getOrElse(UnitOfMeasurement.Unknown)), @@ -272,13 +272,13 @@ private[kamon] class MetricsImpl(config: Config) extends Metrics { } def removeMinMaxCounter(name: String, tags: Map[String, String]): Boolean = - _trackedEntities.remove(Entity(name, "min-max-counter", tags)).isDefined + _trackedEntities.remove(Entity(name, SingleInstrumentEntityRecorder.MinMaxCounter, tags)).isDefined def registerGauge(name: String, valueCollector: CurrentValueCollector, tags: Map[String, String] = Map.empty, unitOfMeasurement: Option[UnitOfMeasurement] = None, dynamicRange: Option[DynamicRange] = None, refreshInterval: Option[FiniteDuration] = None): Gauge = { - val gaugeEntity = Entity(name, "gauge", tags) + val gaugeEntity = Entity(name, SingleInstrumentEntityRecorder.Gauge, tags) val recorder = _trackedEntities.atomicGetOrElseUpdate(gaugeEntity, { val factory = instrumentFactory(gaugeEntity.category) GaugeRecorder(MinMaxCounterKey(gaugeEntity.category, unitOfMeasurement.getOrElse(UnitOfMeasurement.Unknown)), @@ -289,12 +289,12 @@ private[kamon] class MetricsImpl(config: Config) extends Metrics { } def removeGauge(name: String, tags: Map[String, String]): Boolean = - _trackedEntities.remove(Entity(name, "gauge", tags)).isDefined + _trackedEntities.remove(Entity(name, SingleInstrumentEntityRecorder.Gauge, tags)).isDefined def registerCounter(name: String, tags: Map[String, String] = Map.empty, unitOfMeasurement: Option[UnitOfMeasurement] = None, dynamicRange: Option[DynamicRange] = None): Counter = { - val counterEntity = Entity(name, "counter", tags) + val counterEntity = Entity(name, SingleInstrumentEntityRecorder.Counter, tags) val recorder = _trackedEntities.atomicGetOrElseUpdate(counterEntity, { val factory = instrumentFactory(counterEntity.category) CounterRecorder(CounterKey(counterEntity.category, unitOfMeasurement.getOrElse(UnitOfMeasurement.Unknown)), @@ -305,7 +305,7 @@ private[kamon] class MetricsImpl(config: Config) extends Metrics { } def removeCounter(name: String, tags: Map[String, String]): Boolean = - _trackedEntities.remove(Entity(name, "counter", tags)).isDefined + _trackedEntities.remove(Entity(name, SingleInstrumentEntityRecorder.Counter, tags)).isDefined def entity[T <: EntityRecorder](recorderFactory: EntityRecorderFactory[T], entity: Entity): T = { _trackedEntities.atomicGetOrElseUpdate(entity, { diff --git a/kamon-core/src/main/scala/kamon/metric/instrument/Instrument.scala b/kamon-core/src/main/scala/kamon/metric/instrument/Instrument.scala index 59b4b443..089dbeec 100644 --- a/kamon-core/src/main/scala/kamon/metric/instrument/Instrument.scala +++ b/kamon-core/src/main/scala/kamon/metric/instrument/Instrument.scala @@ -33,14 +33,6 @@ trait InstrumentSnapshot { def merge(that: InstrumentSnapshot, context: CollectionContext): InstrumentSnapshot } -class InstrumentType private[kamon] (val id: Int) extends AnyVal -object InstrumentTypes { - val Histogram = new InstrumentType(1) - val MinMaxCounter = new InstrumentType(2) - val Gauge = new InstrumentType(3) - val Counter = new InstrumentType(4) -} - trait CollectionContext { def buffer: LongBuffer } @@ -51,3 +43,11 @@ object CollectionContext { } } +sealed trait InstrumentType + +object InstrumentTypes { + case object Histogram extends InstrumentType + case object MinMaxCounter extends InstrumentType + case object Gauge extends InstrumentType + case object Counter extends InstrumentType +} diff --git a/kamon-core/src/main/scala/kamon/metric/instrument/UnitOfMeasurement.scala b/kamon-core/src/main/scala/kamon/metric/instrument/UnitOfMeasurement.scala index f2a061d1..c5a1b81a 100644 --- a/kamon-core/src/main/scala/kamon/metric/instrument/UnitOfMeasurement.scala +++ b/kamon-core/src/main/scala/kamon/metric/instrument/UnitOfMeasurement.scala @@ -16,17 +16,20 @@ package kamon.metric.instrument +/** + * A UnitOfMeasurement implementation describes the magnitude of a quantity being measured, such as Time and computer + * Memory space. Kamon uses UnitOfMeasurement implementations just as a informative companion to metrics inside entity + * recorders and might be used to scale certain kinds of measurements in metric backends. + */ trait UnitOfMeasurement { def name: String def label: String - def factor: Double } object UnitOfMeasurement { case object Unknown extends UnitOfMeasurement { val name = "unknown" val label = "unknown" - val factor = 1D } def isUnknown(uom: UnitOfMeasurement): Boolean = @@ -35,19 +38,18 @@ object UnitOfMeasurement { def isTime(uom: UnitOfMeasurement): Boolean = uom.isInstanceOf[Time] + def isMemory(uom: UnitOfMeasurement): Boolean = + uom.isInstanceOf[Memory] + } +/** + * UnitOfMeasurement representing time. + */ case class Time(factor: Double, label: String) extends UnitOfMeasurement { val name = "time" - /** - * Scale a value from this scale factor to a different scale factor. - * - * @param toUnit Time unit of the expected result. - * @param value Value to scale. - * @return Equivalent of value on the target time unit. - */ - def scale(toUnit: Time)(value: Long): Double = + def scale(toUnit: Time)(value: Double): Double = (value * factor) / toUnit.factor } @@ -58,8 +60,14 @@ object Time { val Seconds = Time(1, "s") } +/** + * UnitOfMeasurement representing computer memory space. + */ case class Memory(factor: Double, label: String) extends UnitOfMeasurement { val name = "bytes" + + def scale(toUnit: Memory)(value: Double): Double = + (value * factor) / toUnit.factor } object Memory { |