【问题标题】:How to query the number of active sessions with JBoss Wildfly?如何使用 JBoss Wildfly 查询活动会话数?
【发布时间】:2015-05-28 01:07:09
【问题描述】:

我们曾经使用以下代码查询活动会话计数,直到 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 访问相同的信息。

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

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

JBoss 7 中对-Dorg.apache.tomcat.util.ENABLE_MODELER=true 的旧引用也没有帮助。我通过MBean "jboss.web:type=Manager,path=/,host=localhost" not found 提出的旧问题不再有效。

【问题讨论】:

    标签: jmx wildfly wildfly-8


    【解决方案1】:

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

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

    如果你使用的是maven,添加如下依赖。

        <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"

    更多详情请见https://docs.jboss.org/author/display/WFLY8/JMX+subsystem+configuration

    【讨论】:

    • 工作...使用MBeanServerLocator.locateJBoss().getAttribute(new ObjectName("jboss.as:deployment=Project-ear.ear,subdeployment=Project-web.war,subsystem=undertow"), "activeSessions");...
    猜你喜欢
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-29
    • 1970-01-01
    • 1970-01-01
    • 2018-10-10
    • 1970-01-01
    相关资源
    最近更新 更多