Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.7
-
None
-
Novice
Description
A JMX client program such as monitoring platform (Nagios plugin, HypericHQ, ...) retrieve metrics like AvgResponseTime per minute.
One way to retrieve data is to fetch value every minute and reset counter immediately after.
However, if no calls to the service has been made since last reset, you get an ArithmeticException "divide by zero" when calling ResponseTimeCounterMBean.getAvgResponseTime()
I suggest handling this case by returning 0 or -1 instead, thus avoiding exception and alarming stacktrace on the monitoring client side.
ResponseTimeCounter.getAvgResponseTime()
public Number getAvgResponseTime() { if (_invocations.get() == 0) { return -1; // avoid divide by 0; } return (int)(totalHandlingTime / invocations.get()); }