Commits

Anonymous committed 8fb12e0

Fix for division by zero error when there is no traffic.

Comments (0)

Files changed (1)

src/ApacheLogtailer.py

+# -*- coding: utf-8 -*-
 ###
 ###  This plugin for logtailer will crunch apache logs and produce these metrics:
 ###    * hits per second
         # crunch data to how you want to report it
         hits_per_second = mydata['num_hits'] / check_time
         gets_per_second = mydata['num_gets'] / check_time
-        avg_req_time = mydata['req_time'] / mydata['num_hits']
+        if (mydata['num_hits'] != 0):
+             avg_req_time = mydata['req_time'] / mydata['num_hits']
+        else:
+             avg_req_time = 0
         two_per_second = mydata['num_two'] / check_time
         three_per_second = mydata['num_three'] / check_time
         four_per_second = mydata['num_four'] / check_time
         ninetieth_list = mydata['ninetieth']
         ninetieth_list.sort()
         num_entries = len(ninetieth_list)
-        ninetieth_element = ninetieth_list[int(num_entries * 0.9)]
+        if (num_entries != 0 ):
+             ninetieth_element = ninetieth_list[int(num_entries * 0.9)]
+        else:
+             ninetieth_element = 0
 
         # package up the data you want to submit
         hps_metric = GangliaMetricObject('apache_hits', hits_per_second, units='hps')