This is the way (to record metrics)
This is the Kotlin metrics client. It uses kotlinx coroutines to manage background network interactions; you'll need to at least attach it to a framework-provided dispatcher if you don't use coroutines already. If you do then you probably know where you want to put the long-lived background job that emits metrics for your app.
Run the goodmetrics server on localhost.
repositories {
maven {
name = "jitpack"
setUrl("https://jitpack.io")
}
}
dependencies {
implementation("com.github.WarriorOfWire:goodmetrics_kotlin:$goodmetricsVersion")
}
fun main() {
val metricsBackgroundScope = CoroutineScope(Dispatchers.Default)
val (emitterJob, metricsFactory) = metricsBackgroundScope.normalConfig()
for (i in 1..1000) {
metricsFactory.record("demo_app") { metrics ->
metrics.measureI("iteration", i)
metrics.dimensionBool("random_boolean", Random.nextBoolean())
metrics.measureF("random_float", Random.nextFloat())
metrics.dimensionString("host", Inet4Address.getLocalHost().hostName)
}
}
metricsBackgroundScope.cancel()
}