如何查询JBoss Wildfly的活动会话数? [英] How to query the number of active sessions with JBoss Wildfly?

查看:74
本文介绍了如何查询JBoss Wildfly的活动会话数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们过去一直使用以下代码来查询活动会话数,直到JBoss 7:

We used to query the active session count by using the following code up to JBoss 7:

ObjectName name = new ObjectName(jboss.web:type=Manager,path=/MyWebApp,host=default-host);
MBeanServer jboss = MBeanServerLocator.locateJBoss();
this.sessions = new Long((Integer) jboss.getAttribute(name, "activeSessions"));

不再与JBoss Wildfly一起使用.我找不到真正的文档来访问与当前版本的JBoss AS相同的信息.

That no longer works with JBoss Wildfly. I can't really find the proper documentation to access the same information with the current version of JBoss AS.

我遇到了一些链接,例如 http://blog.akquinet.de/2014/09/15/monitoring-the-jboss-eap-wildfly-application-server-with-the- command-line-interface-cli/表示该信息的位置完全不同-但我不知道如何通过Java代码访问它.

I've come across some links like http://blog.akquinet.de/2014/09/15/monitoring-the-jboss-eap-wildfly-application-server-with-the-command-line-interface-cli/ which imply a totally different location of that information – but I can't figure out how to access it via Java code.

/deployment=example.ear/subdeployment=example-web.war/subsystem=under

JBoss 7中对-Dorg.apache.tomcat.util.ENABLE_MODELER=true的旧引用也无济于事.我的旧问题通过​​ MBean 不再起作用.

The old reference to -Dorg.apache.tomcat.util.ENABLE_MODELER=true from JBoss 7 didn't help either. My older question via MBean "jboss.web:type=Manager,path=/,host=localhost" not found doesn't work anymore.

推荐答案

假设您正在部署WAR文件; ObjectName应该类似于jboss.as:deployment=YourWAR.war,subsystem=undertow.

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

请注意,在使用WildFly的情况下-管理本机端口是9990而不是9999.

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

如果您使用的是maven,请添加以下依赖项.

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>

示例示例:

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

如果您的WAR文件捆绑在EAR文件中;那么ObjectName应该类似于jboss.as:deployment=YourEAR.ear,subdeployment=YourWAR.war,subsystem=undertow"

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"

有关更多详细信息,请参见 https://docs.jboss.org /author/display/WFLY8/JMX + subsystem + configuration

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

这篇关于如何查询JBoss Wildfly的活动会话数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆