It’s possible to do it with Metrics using metrics-...
# ktor
h
It’s possible to do it with Metrics using metrics-servlet but nothing with metrics in Ktor.
d
If you copy over the code for micrometer in https://github.com/ktorio/ktor/pull/718, you just install it:
Copy code
val globalRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT) // Or dropwizard, check micrometer docs..
		install(Metrics) {
			registry = globalRegistry
			meterBinders = listOf()
		}
and use this in your Routing:
Copy code
get("/metrics") {
				call.respondText { (application.feature(Metrics).registry as PrometheusMeterRegistry).scrape() }
			}
, I don't know how similar it is with the original implementation though...
h
Thanks a lot, I have reach one step further but I am blocked again 😞
This is the code I have used
Copy code
get<MetricsLocation> {
                    val meters = feature(Metrics)
                        .registry
                        .gauges
                        .map { (key, value) -> Pair(key, value.value) }
                    //.mapValues { entry -> entry.value.value }

                    //val katalogStats = KatalogStats.from(meters)
                    call.respond {
                        meters
                    }
                }
in a route and it works perfect if I am using a call.respondText method and doing the serialization myself with Gson
but if I want to do as it is done in my example, i get a null in the response
I guess Gson has a pb to serialize my object ?
it is a LinkedHashMap
d
Maybe type erasure?
Why are you transforming the metrics?
If you let the lib do all the work, you could just serve it up with respondText and be done with it 🙂
If you use my code, just don't forget to configure a histogram for request timing (I hope I'll get to that change soon...)
h
Sorry Dave, I don’t understand your last sentence. And I try to transform the metrics because I want to expose it as a Json Rest API and not in the for of a flat text.
d
Who's the consumer of the metrics? @hdarritchon
Some timedb like Prometheus or Influx?
Or some kind of custom service?
h
@dave08 my ops right now with it’s tools but I think we plan to have some tools also on their own to have look on it
@dave08 I found my mistake 🙂 I was using a lambda with the respond instead of the method call. This way it works nice 🙂 Thanks a lot for your help. I will have a look to timedb, it could be interesting
d
The most popular one nowadays is Prometheus.
Good luck.
h
thx