Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieving websocket connections via jmx #5122

Closed
sagarikat-26 opened this issue Aug 6, 2020 · 9 comments
Closed

Retrieving websocket connections via jmx #5122

sagarikat-26 opened this issue Aug 6, 2020 · 9 comments
Assignees
Labels

Comments

@sagarikat-26
Copy link

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 ?

@lachlan-roberts
Copy link
Contributor

@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?

@sagarikat-26
Copy link
Author

@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 .

@lachlan-roberts
Copy link
Contributor

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.

@sbordet
Copy link
Contributor

sbordet commented Aug 6, 2020

@lachlan-roberts perhaps we should make a WebSocketConnectionStatistics so that it can be used out of the box by users?

lachlan-roberts added a commit that referenced this issue Aug 6, 2020
…ctionStatistics

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
lachlan-roberts added a commit that referenced this issue Aug 6, 2020
…n SessionTracker

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
@sagarikat-26
Copy link
Author

@lachlan-roberts when will this parameter be available in which release ?

@lachlan-roberts lachlan-roberts added this to To do in Jetty 9.4.32 via automation Aug 13, 2020
@lachlan-roberts
Copy link
Contributor

@sagarika-hp the PR is still under review but will likely be merged before a 9.4.32 release.

lachlan-roberts added a commit that referenced this issue Aug 18, 2020
Issue #5122 - Improve connection statistics for WebSocket
@lachlan-roberts
Copy link
Contributor

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);

Jetty 9.4.32 automation moved this from To do to Done Sep 15, 2020
@joakime
Copy link
Contributor

joakime commented Sep 15, 2020

@lachlan-roberts is this documented yet?

@lachlan-roberts
Copy link
Contributor

@joakime I don't think so, I'll put up a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Jetty 9.4.32
  
Done
Development

No branches or pull requests

4 participants