I'm trying to use JMX API to get active session counts for a web application.
I've been reading JMX tutorial and documentation, but they are giving me the overview of what the technology is. I just can't pinpoint to what I need, yet.
You can accomplish this by using something like JConsole or JVisualVM once you configure your app server to expose a JMX port. You don't mention which app server you're using but for Tomcat, it's described here: http://tomcat.apache.org/tomcat-5.5-doc/monitoring.html. Once you connect with JConsole, Tomcat exposes an MBean which has session information but again it depends which container you use.
ObjectName name = new ObjectName("Catalina:type=Manager,path=/NAME_OF_APP,host=localhost");
ManagementFactory.getPlatformMBeanServer().getAttribute(name, "activeSessions");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With