views:

44

answers:

3

In my particular web app I need a heavy load statistics, such as "requests per minute". How to obtain this value within Servlet API based webapp?

+3  A: 

Almost all containers allow instrumentation data to be queried using JMX. It could be you have to install a plugin.

The exact content is container specific, but it is pretty straightforward.

Here are the docs related to tomcat for example.

Peter Tillemans
+1  A: 

The easies way to get to these statistics is to configure Tomcat access logs. There are some tools available to parse these logs but you can do requests per minute with a simple script.

leonm
+1  A: 

Well not coming from a servlet background, I would be tempted to do it the old fashioned way: count as you process.

If this was PHP, ASPNET or Django, I would keep a memcache key to store the current minute, and another key for a counter.

When the action you want to track occurs, check to see if the minute is the same as the current one. If it is, increment the counter and if it's not, save the old count to database, save the new current minute and start the counter from zero.

You can extend it quite easily to track different actions by adding the action to the memcache keys.

Oli
Let me update your approach a little: I count as I process, but don't drop value to zero, and don't store current minute. I just query counter from time to time and store the time of the last query event, and the value at that moment. This makes things easy: I have time difference between now and previous query, and I have value difference. This is all needed to calculate.
Shaman