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/scala/kamon/metric/instrument/UnitOfMeasurement.scala | |
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/scala/kamon/metric/instrument/UnitOfMeasurement.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/metric/instrument/UnitOfMeasurement.scala | 28 |
1 files changed, 18 insertions, 10 deletions
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 { |