Getting a list of active sessions in Tomcat using Java

后端 未结 9 1464
醉梦人生
醉梦人生 2020-12-08 20:34

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

9条回答
  •  甜味超标
    2020-12-08 21:24

    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
    }
    

提交回复
热议问题