https://kotlinlang.org logo
#http4k
Title
# http4k
x

xuemin.guan

10/23/2018, 10:21 AM
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

arve

10/23/2018, 10:38 AM
I guess you can create another
Http4kServer
and tie the metrics endpoints to that server instead?
x

xuemin.guan

10/23/2018, 10:52 AM
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

arve

10/23/2018, 10:54 AM
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

xuemin.guan

10/23/2018, 11:10 AM
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

arve

10/23/2018, 11:12 AM
No problem, good luck! 🙂
d

dave

10/23/2018, 8:29 PM
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

xuemin.guan

10/24/2018, 1:15 PM
cheers guys!
4 Views