Search code examples
javaspringspring-bootmetricsspring-websocket

Exposing metrics about current Websocket connections with Spring


For my dashboarding application I want to monitor my Spring Boot based application with internal Spring metrics. Therefor I am using the spring-boot-actuator dependency which is exposing a lot of internal metrics. There are a lot of HTTP based metrics and Tomcat metrics like current sessions, amount of HTTP calls of status X and so on. I coulnd't find any information regarding my Websocket connections.

Is there any build-in out of the box metrics exposing tool for the current Websockets with Spring or do I have to create my own metrics (e.g. for showing the data in Grafana with Prometheus) and have to manually register for example a counter which is updated when I receive a SessionConnectEvent or SessionConnectEvent?

Thanks in advance!


Solution

  • If you are using STOMP over WebSocket, Spring aggregates information about internal state and counters from key infrastructure components of the setup in WebSocketMessageBrokerStats, by default this is logged every 30 seconds. It is created as a Spring bean and can be easily autowired. This is an example of the information you'll get: WebSocketMessageBrokerStats output

    There are no actuator endpoints currently, but I've created them as part of my Spring WebSocket Chat sample: