Hi, I am trying to understand how to expose jvm me...
# http4k
Hi, I am trying to understand how to expose jvm metrics from my Jetty Http4Server .. I've read this https://www.http4k.org/guide/howto/monitor_http4k/ but still not sure on what I need to do. Do I need to expose a route which outputs the metrics? Or is configuring jetty enough? Or perhaps do i need to collect jvm metrics myself (threads count, memory consumption, these things I am interested in) "manually" ? thanks
If you're using Micrometer it has some standard stuff so you don't have to collect everything yourself. E.g. https://micrometer.io/docs/ref/jvm. Once you've collected metrics, you need to make them available. If you're using prometheus to collect the metrics from your services, the way you'd do this is to have the service expose a metrics endpoint. E.g. let's say you're collecting metrics into a
then you would have a route something like
Copy code
        "/metrics" bind GET to {
Thanks a lot. But this leads me to another question. Doing something like this means having a kind of "global" metrics collecting object, right? What is the threading model of http4k? Underneath the http4kserver is there still a kind of servlet? With a thread per request model? If so how can I put a metrics registry at application (not session nor request) level? 🤔
You create the metrics registry when you’re wiring up your service, so you have just one. You have just one http server right? You expose a route from that with the metrics. You can then pass the metrics registry around wherever it needs to go (to other routes / application code if they’re exposing metrics) and just use it (it’s thread safe as far as I’m aware, but I’d always check the docs anyway rather than trusting what some person on the internet said 😂 🤷) The threading model of http4k depends on the http server implementation you chose. It’s provided by that rather than http4k itself. So in your case, whatever Jetty does.
😄 👍 thanks a lot!
Micrometer / Prometheus also has a simple HTTP server built-in, if you want to expose metrics at another port than your main server,
Thanks I will check it out 👍