hi, we were recommended by our OPs to expose our m...
# http4k
x
hi, we were recommended by our OPs to expose our metrics on a different port from our app’s main HTTP server. I wonder if there is a way in http4k do so, ie expose a RoutingHttpHandler on a different port from the app?
a
I guess you can create another
Http4kServer
and tie the metrics endpoints to that server instead?
x
hi, doesn’t that mean my app and my meter are running in 2 different server/processes then? Which means the meter is not measuring the app?
🤔 1
a
Copy code
val registry = SimpleMeterRegistry()

val app = MetricFilters.Server.RequestCounter(registry)
        .then(MetricFilters.Server.RequestTimer(registry))
        .then(routes(/* Your routes here*/))
        .asServer(Jetty(port))

val metrics = routes(
      "/metrics" bind GET to {registry.someMethodToFetchRelevantMetrics }
).asServer(Jetty(otherPort))
one process, two "servers"
☝️ 1
x
ah, I see. it is in the official document. Thanks Arve for pointing it out.
This solves my problem.
Thank you very much, Arve. I should have read the documentation more carefully.
a
No problem, good luck! 🙂
d
We currently run dual http4k servers for running inside k8s. Similar arrangement - one does readiness/liveness/metrics collection, the other serves the traffic. You just need to have a composite "service" which will start and stop both.
x
cheers guys!