blob: 11876e992340aa86763a250279da4a21336fc033 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package kamon.metric
import java.util.concurrent.atomic.AtomicLong
import kamon.util.MeasurementUnit
trait Gauge {
def measurementUnit: MeasurementUnit
def increment(): Unit
def increment(times: Long): Unit
def decrement(): Unit
def decrement(times: Long): Unit
def set(value: Long): Unit
}
class AtomicLongGauge(name: String, tags: Map[String, String], val measurementUnit: MeasurementUnit)
extends SnapshotableGauge {
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(): MetricValue =
MetricValue(name, tags, measurementUnit, currentValue.get())
}
|