views:

83

answers:

2

We would like to monitor HTTP error codes (e.g. per minute) for later graphing.

How can we expose HTTP return (error) codes with JMX?

Are there code samples or have you done something like that? Is this contained in Tomcat per default?

About the implementation: Should the code increase a JMX counter and set it to 0 every minute? Thanks for ideas.

+1  A: 

Add a JMX bean which has one field per HTTP error you care about. Increment each field as errors drop in. The JMX console will turn that into a nice curve. I wouldn't reset the value but that mostly depends on what features your console has to show a statistic on a value.

Aaron Digulla
And set the JMX value from a Servlet Filter at each request?
Stephan Schmidt
+1  A: 

If you're looking to derive rates of errors and graph those, you're better off having the server return a total count of errors. That way the client can then derive a rate independent of the server (e.g. per minute/per hour/per day).

More importantly, you won't miss any temporary surges in the data. If the server is deriving a rate and your client process doesn't pick it up (if it's not monitoring at that particular time, say), then it's lost forever. Whereas maintaining a count will record the total number of errors.

SNMP agents (and similar) take this approach, allowing clients to monitor and derive values as they see fit.

Brian Agnew