diff options
author | Ivan Topolnjak <ivantopo@gmail.com> | 2017-04-28 14:56:02 +0200 |
---|---|---|
committer | Ivan Topolnjak <ivantopo@gmail.com> | 2017-04-28 15:00:06 +0200 |
commit | f24c1a7a4b96dcfb2609c6f512f34dd6d54de439 (patch) | |
tree | 9e32bb0018a8c708e2dd33d5c30cd6786ed48731 /kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala | |
parent | f5e70695ad0124cd5cd648d186d5174c7b121266 (diff) | |
download | Kamon-f24c1a7a4b96dcfb2609c6f512f34dd6d54de439.tar.gz Kamon-f24c1a7a4b96dcfb2609c6f512f34dd6d54de439.tar.bz2 Kamon-f24c1a7a4b96dcfb2609c6f512f34dd6d54de439.zip |
implement MinMaxCounter and Gauge, include them in the InstrumentFactory
Diffstat (limited to 'kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala | 27 |
1 files changed, 25 insertions, 2 deletions
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 bb31e30a..5263d258 100644 --- a/kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala +++ b/kamon-core/src/main/scala/kamon/metric/instrument/Gauge.scala @@ -1,5 +1,7 @@ package kamon.metric.instrument +import java.util.concurrent.atomic.AtomicLong + import kamon.metric.Entity import kamon.util.MeasurementUnit @@ -13,6 +15,27 @@ trait Gauge { def set(value: Long): Unit } -object Gauge { - def apply(entity: Entity, name: String): Gauge = ??? + +class AtomicLongGauge(entity: Entity, name: String, val measurementUnit: MeasurementUnit) + extends Gauge with SingleValueSnapshotInstrument { + + private val currentValue = new AtomicLong(0L) + + def increment(): Unit = + currentValue.incrementAndGet() + + def increment(times: Long): Unit = + currentValue.addAndGet(times) + + def decrement(): Unit = + currentValue.decrementAndGet() + + def decrement(times: Long): Unit = + currentValue.addAndGet(-times) + + def set(value: Long): Unit = + currentValue.set(value) + + def snapshot(): SingleValueSnapshot = + SingleValueSnapshot(name, measurementUnit, currentValue.get()) } |