How to get current number of connections of an akka-http application?

I want to get the current number of connections from within an akka-http application. Is there any way to get hold of it?

The end goal is to be able to publish it to prometheus regularly for monitoring the load of the service.

Not a real answer to your question, but I’d think of keeping track of those via an external proxy/load-balancer that collects metrics for http traffic.
That way the application code is not directly involved in instrumentation of the system.

If you use the low level api for http you can keep track of the number of in-flight connections:

Http().bind(hostName, port)
.to(Sink.foreach { con =>
//increment counter
con.handleWith(routes)
//decrement counter
}).run()

Hope it helps.

Hi @bilal-fazlani If you are looking for a commercial solution you should check out Lightbend Telemetry It does help report akka http metrics to Prometheus. https://developer.lightbend.com/docs/telemetry/current/plugins/prometheus/prometheus.html

Thank you!