Add STOMP/WebSocket stats collection
This change adds collection of stats in key infrastructure components of the WebSocket message broker config setup and exposes the gathered information for logging and viewing (e.g. via JMX). WebSocketMessageBrokerStats is a single class that assembles all gathered information and by default logs it once every 15 minutes. Application can also easily expose to JMX through an MBeanExporter. A new section in the reference documentation provides a summary of the available information. Issue: SPR-11739
This commit is contained in:
@@ -245,6 +245,17 @@ public class MessageBrokerBeanDefinitionParserTests {
|
||||
catch (NoSuchBeanDefinitionException ex) {
|
||||
// expected
|
||||
}
|
||||
|
||||
String name = "webSocketMessageBrokerStats";
|
||||
WebSocketMessageBrokerStats stats = this.appContext.getBean(name, WebSocketMessageBrokerStats.class);
|
||||
assertEquals("WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), " +
|
||||
"0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], " +
|
||||
"stompSubProtocol[processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], " +
|
||||
"stompBrokerRelay[0 sessions, relayhost:1234 (not available), processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], " +
|
||||
"inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " +
|
||||
"outboundChannelpool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " +
|
||||
"sockJsScheduler[pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0]",
|
||||
stats.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.springframework.web.servlet.HandlerMapping;
|
||||
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
|
||||
import org.springframework.web.socket.TextMessage;
|
||||
import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.config.WebSocketMessageBrokerStats;
|
||||
import org.springframework.web.socket.handler.TestWebSocketSession;
|
||||
import org.springframework.web.socket.messaging.StompSubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.StompTextMessageBuilder;
|
||||
@@ -51,6 +52,7 @@ import org.springframework.web.socket.messaging.SubProtocolHandler;
|
||||
import org.springframework.web.socket.messaging.SubProtocolWebSocketHandler;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Test fixture for
|
||||
@@ -134,6 +136,20 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
|
||||
assertTrue(executor.getRemoveOnCancelPolicy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webSocketMessageBrokerStats() {
|
||||
String name = "webSocketMessageBrokerStats";
|
||||
WebSocketMessageBrokerStats stats = this.config.getBean(name, WebSocketMessageBrokerStats.class);
|
||||
assertEquals("WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), " +
|
||||
"0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], " +
|
||||
"stompSubProtocol[processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], " +
|
||||
"stompBrokerRelay[null], " +
|
||||
"inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " +
|
||||
"outboundChannelpool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], " +
|
||||
"sockJsScheduler[pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0]",
|
||||
stats.toString());
|
||||
}
|
||||
|
||||
|
||||
@Controller
|
||||
static class TestController {
|
||||
|
||||
Reference in New Issue
Block a user