Permalink
Browse files

Prevent divided by zero error

  • Loading branch information...
1 parent 421466c commit b82fbda351e740166132a97a2e0b2c610a83bf8d @bcui6611 bcui6611 committed Jun 13, 2012
Showing with 54 additions and 19 deletions.
  1. +2 −2 Makefile.am
  2. +4 −2 analyzer.py
  3. +34 −11 cluster_stats.py
  4. +12 −3 diskqueue_stats.py
  5. +2 −1 healthchecker
View
4 Makefile.am
@@ -53,7 +53,7 @@ bdist:
mkdir -p $(TMP_DIR)/$(PROJECT_NAME)/simplejson
cp $(PROJECT_NAME) *.py $(TMP_DIR)/$(PROJECT_NAME)
cp -rf $(CHEETAH_LIB) $(JSON_LIB) report-htm.tmpl LICENSE $(TMP_DIR)/$(PROJECT_NAME)
- (cd $(TMP_DIR); tar cf - $(PROJECT_NAME)) | gzip -9 > healtherChecker_`cat $(TMP_VER)`-`uname -s`.`uname -m`.tar.gz
- echo created healtherchecker_`cat $(TMP_VER)`-`uname -s`.`uname -m`.tar.gz
+ (cd $(TMP_DIR); tar cf - $(PROJECT_NAME)) | gzip -9 > healthchecker_`cat $(TMP_VER)`-`uname -s`.`uname -m`.tar.gz
+ echo created healthchecker_`cat $(TMP_VER)`-`uname -s`.`uname -m`.tar.gz
rm -rf $(TMP_DIR)
View
6 analyzer.py
@@ -1,3 +1,4 @@
+import os
import sys
import datetime
import logging
@@ -172,9 +173,10 @@ def run_report(self, txtfile, htmlfile, verbose):
print >> f, util.pretty_print(report)
f.close()
-
+
+ mydir = os.path.dirname(sys.argv[0])
f = open(htmlfile, 'w')
- print >> f, Template(file="report-htm.tmpl", searchList=[dict])
+ print >> f, Template(file=os.path.join(mydir, "report-htm.tmpl"), searchList=[dict])
f.close()
sys.stderr.write("\nThe run finished successfully. Please find output result at '{0}'".format(htmlfile))
View
45 cluster_stats.py
@@ -36,7 +36,10 @@ def run(self, accessor):
nodeStats = values["nodeStats"]
samplesCount = values["samplesCount"]
for node, vals in nodeStats.iteritems():
- avg = sum(vals) / samplesCount
+ if samplesCount > 0:
+ avg = sum(vals) / samplesCount
+ else:
+ avg = 0
item_avg[counter].append((node, avg))
res = []
active_total = replica_total = 0
@@ -61,7 +64,8 @@ def run(self, accessor):
if len(num_error) > 0:
res.append(("error", num_error))
result[bucket] = res
- result["cluster"] = util.pretty_float(cluster / len(stats_buffer.buckets))
+ if len(stats_buffer.buckets) > 0:
+ result["cluster"] = util.pretty_float(cluster / len(stats_buffer.buckets))
return result
class OpsRatio:
@@ -78,7 +82,10 @@ def run(self, accessor):
nodeStats = values["nodeStats"]
samplesCount = values["samplesCount"]
for node, vals in nodeStats.iteritems():
- avg = sum(vals) / samplesCount
+ if samplesCount > 0:
+ avg = sum(vals) / samplesCount
+ else:
+ avg = 0
ops_avg[counter].append((node, avg))
res = []
read_total = write_total = del_total = 0
@@ -94,9 +101,12 @@ def run(self, accessor):
del_ratio = delete[1] * 100 / count
del_total += del_ratio
res.append((read[0], "{0}% reads : {1}% writes : {2}% deletes".format(int(read_ratio+.5), int(write_ratio+.5), int(del_ratio+.5))))
- read_total /= len(ops_avg['cmd_get'])
- write_total /= len(ops_avg['cmd_set'])
- del_total /= len(ops_avg['delete_hits'])
+ if len(ops_avg['cmd_get']) > 0:
+ read_total /= len(ops_avg['cmd_get'])
+ if len(ops_avg['cmd_set']) > 0:
+ write_total /= len(ops_avg['cmd_set'])
+ if len(ops_avg['delete_hits']) > 0:
+ del_total /= len(ops_avg['delete_hits'])
res.append(("total", "{0}% reads : {1}% writes : {2}% deletes".format(int(read_total+.5), int(write_total+.5), int(del_total+.5))))
result[bucket] = res
@@ -118,13 +128,17 @@ def run(self, accessor):
num_error = []
for node, vals in nodeStats.iteritems():
#a, b = util.linreg(timestamps, vals)
- value = sum(vals) / samplesCount
+ if samplesCount > 0:
+ value = sum(vals) / samplesCount
+ else:
+ value = 0
total += value
if value > accessor["threshold"]:
num_error.append({"node":node, "value":value})
trend.append((node, util.pretty_float(value)))
data.append(value)
- total /= len(nodeStats)
+ if len(nodeStats) > 0:
+ total /= len(nodeStats)
trend.append(("total", util.pretty_float(total)))
trend.append(("variance", util.two_pass_variance(data)))
if len(num_error) > 0:
@@ -149,7 +163,10 @@ def run(self, accessor):
total = 0
data = []
for node, vals in nodeStats.iteritems():
- avg = sum(vals) / samplesCount
+ if samplesCount > 0:
+ avg = sum(vals) / samplesCount
+ else:
+ avg = 0
trend.append((node, util.size_label(avg)))
data.append(avg)
#print data
@@ -178,11 +195,17 @@ def run(self, accessor):
start_cluster += b
end_val = a * timestamps[-1] + b
end_cluster += end_val
- rate = (end_val * 1.0 / b - 1.0) * 100
+ if b > 0:
+ rate = (end_val * 1.0 / b - 1.0) * 100
+ else:
+ rate = 0
trend.append((node, util.pretty_float(rate) + "%"))
result[bucket] = trend
if len(stats_buffer.buckets) > 0:
- rate = (end_cluster * 1.0 / start_cluster - 1.0) * 100
+ if start_cluster > 0:
+ rate = (end_cluster * 1.0 / start_cluster - 1.0) * 100
+ else:
+ rate = 0
result["cluster"] = util.pretty_float(rate) + "%"
return result
View
15 diskqueue_stats.py
@@ -12,7 +12,10 @@ def run(self, accessor):
nodeStats = values["nodeStats"]
samplesCount = values["samplesCount"]
for node, vals in nodeStats.iteritems():
- avg = sum(vals) / samplesCount
+ if samplesCount > 0:
+ avg = sum(vals) / samplesCount
+ else:
+ avg = 0
if avg > accessor["threshold"]["high"]:
disk_queue_avg_error.append({"node":node, "level":"red", "value":avg})
elif avg > accessor["threshold"]["low"]:
@@ -81,9 +84,15 @@ def run(self, accessor):
nodeStats = drain_values["nodeStats"]
samplesCount = drain_values["samplesCount"]
for node, vals in nodeStats.iteritems():
- avg = sum(vals) / samplesCount
+ if samplesCount > 0:
+ avg = sum(vals) / samplesCount
+ else:
+ avg = 0
disk_len_vals = len_values["nodeStats"][node]
- len_avg = sum(disk_len_vals) / samplesCount
+ if samplesCount > 0:
+ len_avg = sum(disk_len_vals) / samplesCount
+ else:
+ len_avg = 0
if avg < accessor["threshold"]["drainRate"] and len_avg > accessor["threshold"]["diskLength"]:
disk_queue_avg_error.append({"node":node, "level":"red", "value":avg})
if len(disk_queue_avg_error) > 0:
View
3 healthchecker
@@ -65,7 +65,8 @@ usage: healthChecker CLUSTER USERNAME PASSWORD OPTIONS
CLUSTER:
--cluster=HOST[:PORT] or -c HOST[:PORT] Default port is 8091
-USERNAME:
+USERNAME:
+
-u USERNAME, --user=USERNAME admin username of the cluster
PASSWORD:
-p PASSWORD, --password=PASSWORD admin password of the cluster

0 comments on commit b82fbda

Please sign in to comment.