MBean nested object name in JMX
I noticed that I could add scope to the property list when I looked at jconsole
:
So, what I used was:
"org.apache.cassandra.metrics:type=Cache,scope=CounterCache,name=HitRate"
It's nice to know that it's not documented anywhere...
To get all session ids of tomcat using JConsole which can be found at :-
Catalina > Manager > localhost > /##07 ( > Operations > listSessionIds )
To get the MBean object name of /##07 just click on it on JConsole and it will show the name.(As shown below)
Java code to fetch all the session Ids:
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9999/jmxrmi");
JMXConnector jmxConn = JMXConnectorFactory.connect(url, null);
// Connecting to the MBeanServer
MBeanServerConnection mbsConn = jmxConn.getMBeanServerConnection();
Object sessionIds = mbsConn.invoke(new ObjectName("Catalina:type=Manager,host=localhost,context=/##07"), "listSessionIds", null, null);
System.out.println(sessionIds.toString());
//close jmx connection
jmxConn.close();