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
You can attach a jolokia jvm agent to the running tomcat and query the activeSessions attribute from the relevant MBeans via curl.
java -jar agent.jar start [TOMCAT-PID]
curl 'http://127.0.0.1:8778/jolokia/read/Catalina:context=*,host=*,type=Manager/activeSessions'
java -jar agent.jar stop [TOMCAT-PID]
This will give you something like
{
"request":{
"mbean":"Catalina:context=*,host=*,type=Manager",
"attribute":"activeSessions",
"type":"read"
},
"value":{
"Catalina:context=\/SampleApp,host=localhost,type=Manager":{
"activeSessions":1
}
},
"timestamp":1553105659,
"status":200
}