Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 496
rieckpil Avatar asked Dec 08 '22 15:12

rieckpil


1 Answers

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:

  • Trace Endpoint: exposes WebSocket traces
  • Mappings Endpoint: exposes WebSocket message mappings
  • Stats Endpoint: exposes WebSocketMessageBrokerStats
like image 125
Sergi Almar Avatar answered Jan 13 '23 13:01

Sergi Almar