简体   繁体   中英

List Tomcat connections using JMX

Is there a way to list all connections per deployed jar in Tomcat?

I found this code to list all applications:

JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://31.181.71.213:9999/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url);
MBeanServerConnection server = jmxc.getMBeanServerConnection();
Set<ObjectName> names = server.queryNames(new ObjectName("Catalina:type=Host,*"), null);
Set<String> hostNames = new HashSet<String>();

for (ObjectName on : names)
{
    hostNames.add(on.getKeyProperty("host"));
}

for (String str : hostNames)
{
    ObjectName[] webapps = (ObjectName[]) server.getAttribute(new ObjectName("Catalina:type=Host,host=" + str), "children");
    for (ObjectName ob : webapps)
    {
        String[] appSpl = ob.getKeyProperty("name").split("//localhost");
        // webappNames.add(appSpl[1]);
        System.out.println("Deployed application " + appSpl[1]);
    }
}

But how I can also list the network connections?

Apache ActiveMQ is what you are looking for!

You can achieve the connection statistics using the ActiveMQ MBeans - Connection

Have a look at the Apache ActiveMQ JMX

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM