Created
May 24, 2022 11:58
-
-
Save ChrisBlom/7759f61dfde3dd326f69e93b91e24124 to your computer and use it in GitHub Desktop.
wrapper to create a easy to use timegauge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.micrometer.core.instrument.MeterRegistry | |
import io.micrometer.core.instrument.Tag | |
import java.time.Instant | |
import java.util.concurrent.TimeUnit | |
import java.util.concurrent.atomic.AtomicLong | |
import java.util.function.ToDoubleFunction | |
fun MeterRegistry.timeGaugeMillis(name: String, tags: Iterable<Tag>, initialValue: Long = 0): (Instant) -> Unit { | |
val a = AtomicLong(initialValue) | |
a.apply { | |
val deref = ToDoubleFunction<AtomicLong> { x -> x.get().toDouble() } | |
[email protected]().timeGauge(name, tags, this, TimeUnit.MILLISECONDS, deref) | |
} | |
return { t: Instant -> a.set(t.toEpochMilli()) } | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment