Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Active Session counts with JMX (Java Management Extensions) API

I'm trying to use JMX API to get active session counts for a web application.

  1. Is it possible to use JMX API to get this kind of information?
  2. If yes, how reliable would it be?
  3. Any example code on how to get this done?

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.

like image 550
codingbear Avatar asked Jul 10 '09 23:07

codingbear


2 Answers

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.

like image 111
digitalsanctum Avatar answered Sep 28 '22 09:09

digitalsanctum


ObjectName name = new ObjectName("Catalina:type=Manager,path=/NAME_OF_APP,host=localhost"); 
ManagementFactory.getPlatformMBeanServer().getAttribute(name, "activeSessions");
like image 20
Mateu Avatar answered Sep 28 '22 09:09

Mateu