Search code examples
javatomcattomcat8

Is there a way to maintain current logged in users info in tomcat 8?


Is there a way to maintain current logged in user info in tomcat 8? Like, total number of users currently logged in my system? users active in last 20 minutes? Users idle in last 15 minutes? etc?

I already configured an access log which tells me what apis were requested but that is not giving answering my above questions. I looked around (internet/stackoverflow) but not quite clear on the solution. Thought I could get some help from here.

I am still looking around and I will update this post if I find a solution.

Thanks in advance.


Solution

  • Two options come to mind.

    1. Adjust the properties written in the access log. The format is configurable and perhaps you could write something that would allow you to track the stats you want.

      http://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Log_Valve

      I can't say exactly what you'll want to log, but you can log things like the session id, request headers, response headers and attributes from the session. There's also %u, if you're doing container auth, which should list the authenticated user.

    2. You can connect via JMX and look at the stats published by Tomcat. There's quite a bit of information already. If that's not sufficient, you can always expose more stats through your application & JXM.

      http://docs.oracle.com/javase/tutorial/jmx/