How to query the number of active sessions with JBoss Wildfly?

我的梦境 提交于 2019-12-06 14:57:51

Assuming you are deploying a WAR file; the ObjectName should be something similar to jboss.as:deployment=YourWAR.war,subsystem=undertow.

Note that in case of WildFly - management native port is 9990 instead of 9999.

If you are using maven, add the following dependency.

    <dependency>
        <groupId>org.jboss.remotingjmx</groupId>
        <artifactId>remoting-jmx</artifactId>
        <version>2.0.0.Final</version>
    </dependency>

Sample example:

public static void main(String[] args) throws Exception {

    ObjectName mBeanName = new ObjectName("jboss.as:deployment=wildfly-helloworld-rs.war,subsystem=undertow");

    String host = "localhost";
    int port = 9990;  // management-native port

    String urlString = System.getProperty("jmx.service.url", "service:jmx:http-remoting-jmx://" + host + ":" + port);
    JMXServiceURL serviceURL = new JMXServiceURL(urlString);
    JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
    MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

    System.out.println("Value via JMX: activeSessions: " + connection.getAttribute(mBeanName, "activeSessions"));
    System.out.println("Value via JMX: contextRoot: " + connection.getAttribute(mBeanName, "contextRoot"));
}

If your WAR file is bundled inside an EAR file; then the ObjectName shall be something similar to jboss.as:deployment=YourEAR.ear,subdeployment=YourWAR.war,subsystem=undertow"

For more details, see https://docs.jboss.org/author/display/WFLY8/JMX+subsystem+configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!