Jetty version
9.4.31v
Java version
1.8
Question
I am trying to fetch the connection stats for my websocket server via jmx
so while fetching this mbean
org.eclipse.jetty.io:context=HTTP_1_1@15bb6bea,id=0,type=connectionstatistics
as part of the attributes ,i get the number of current connections value as
connections (long, r) =52
This is the number of HTTP upgrade connections that have happened or it tells me that these are the number of active websocket connection running in my server?. New to jetty so trying to understand the configurations.
And how can i get the number of active websocket connections via jmx ?
@sagarika-hp The ConnectionStatistics can tell you the number of active connections on the Connector, this can include stats from both HTTP connections and WebSocket connections.
When using WebSocket with ConnectionStatistics, there is the HTTP connection used for the HTTP/1.1 websocket upgrade, this is closed and a WebSocket connection is opened. The ConnectionStatistics will give you the stats for both the HTTP and WebSocket connections.
Why do you think 52 is the incorrect value for the number of open connections?
@lachlan-roberts is there a way to find out that if how many connections have got upgraded ? so when we say there are 52 connections how will i know if its an http upgrade connection or a websocket one. I am not saying its a wrong value ..trying to understand how its calculated .
ConnectionStatistics doesn't differentiate between the HTTP connections and the WebSocket ones, it is just giving you stats for all connections on that Connector.
If you want stats for only websocket Connections you could try subclassing it to only get stats for instances of AbstractWebSocketConnection.
new ConnectionStatistics()
{
@Override
public void onOpened(Connection connection)
{
if (connection instanceof AbstractWebSocketConnection)
super.onOpened(connection);
}
@Override
public void onClosed(Connection connection)
{
if (connection instanceof AbstractWebSocketConnection)
super.onClosed(connection);
}
};
You can also get detailed info about the state of open WS sessions through a dump of the SessionTracker.
@lachlan-roberts perhaps we should make a WebSocketConnectionStatistics so that it can be used out of the box by users?
@lachlan-roberts when will this parameter be available in which release ?
@sagarika-hp the PR is still under review but will likely be merged before a 9.4.32 release.
From 9.4.32 we will have the IncludeExcludeConnectionStatistics, which will allow you to only collect stats for specific types of Connection. This can be done with the following java code or the XML equivalent:
IncludeExcludeConnectionStatistics statistics = new IncludeExcludeConnectionStatistics();
statistics.include("org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection");
server.addBeanToAllConnectors(statistics);
@lachlan-roberts is this documented yet?
@joakime I don't think so, I'll put up a PR.
Most helpful comment
@lachlan-roberts perhaps we should make a
WebSocketConnectionStatisticsso that it can be used out of the box by users?