I am developing a project in Java in which I want the count of all active sessions in Tomcat. Based on that I want to see how much of those users are active and actually usi
If you dont need the values in the actual web application, a groovy script can help:
import javax.management.remote.*
import javax.management.*
import groovy.jmx.builder.*
// Setup JMX connection.
def connection = new JmxBuilder().client(port: 4934, host: '192.168.10.6')
connection.connect()
// Get the MBeanServer.
def mbeans = connection.MBeanServerConnection
def activeBean = new GroovyMBean(mbeans, 'Catalina:type=Manager,host=localhost,context=/')
println "Active sessions: " + activeBean['activeSessions']
If you want the actual sessions, you have methods to retrieve them, like:
def sessions = activeBean.listSessionIds().tokenize(' ');