Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-5016

ArithmeticException on ResponseTimeCounterMBean.getAvgResponseTime() after counter reset()

    XMLWordPrintableJSON

Details

    • 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());
      }
      

      Attachments

        Activity

          People

            ffang Freeman Yue Fang
            efe4dsip Emmanuel FOUCHE
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: