Peter Penzov
Peter Penzov

Reputation: 1658

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?

Upvotes: 2

Views: 300

Answers (1)

Arjun
Arjun

Reputation: 3793

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

Upvotes: 1

Related Questions