Reputation: 15063
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.
Upvotes: 6
Views: 38489
Reputation: 2698
ObjectName name = new ObjectName("Catalina:type=Manager,path=/NAME_OF_APP,host=localhost");
ManagementFactory.getPlatformMBeanServer().getAttribute(name, "activeSessions");
Upvotes: 3
Reputation:
The answer given by skaffman is quite helpful, but I would amend that JBoss is able to give you the sessions per webapp by looking for:
host=localhost,path=/your_webapp_context,type=Manager
(replace your_webapp_context with the context of the webapp you are interested in...)
Upvotes: 0
Reputation: 403451
JBoss already exposes the active session count via JMX, but only across the whole server, not per webapp. If you only have one webapp being used, then that should be OK for you.
Go the JMX console on port 8080, and look for the entry called host=localhost,path=/,type=Manager
. Inside that you'll find a entry for active session count.
Upvotes: 1
Reputation: 3299
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.
Upvotes: 5
Reputation: 867
To track the sessions you could use an HttpSessionListener . If you want to expose the active sessions via JMX, you could register a mbean and call it from other applications(see JMX documentation).
Upvotes: 2