Question

I have a program that is receiving an object and doing something with it.

I want to create a monitoring stats on it, such as messages per second, or over 5 minutes.

The way I was thinking of doing this was to increase a int counter, and then set up a system timer to go every second and reset the counter, and then update the results.

Is this a feasible way?
I think it will work, but It might limit me in terms of gaining other stats from the data such as a 5min average, unless I then save that information somewhere else after my timer?

This is not to profile my application, but more to get an understanding of the programs current load.

Was it helpful?

Solution

That would work, however I think you would be better off simply recording each request with a timestamp. That seems to be the lowest level of granularity you are looking at. Not only is that code simpler to write, it will also not have to change when you want to do daily averages, 5 min. averages etc.

If you want to do all of your analysis in code, you could think of setting up a publish subscribe pattern: http://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern.

Your publisher would record each request and a timestamp and send it out to the subscribers. Each subscriber would analyze the data in a different way. For example, you may have a 5 min avg. subscriber that is calculating the 5min avg. and another subscriber that is calculating the 1 second avg.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top