blob: 5263d258e2e08106a34019432288f6b1fd402e53 (
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
41
|
package kamon.metric.instrument
import java.util.concurrent.atomic.AtomicLong
import kamon.metric.Entity
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(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())
}
|