From 1d78356a09fc1ea88b9992248aff4cf6951b2405 Mon Sep 17 00:00:00 2001 From: Bin Cui Date: Thu, 23 Aug 2012 19:31:03 -0700 Subject: [PATCH] Avoid to apply same method twice --- diskqueue_stats.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/diskqueue_stats.py b/diskqueue_stats.py index 4a31649..87d05ac 100755 --- a/diskqueue_stats.py +++ b/diskqueue_stats.py @@ -84,8 +84,9 @@ class ReplicationTrend: def run(self, accessor, scale, threshold=None): result = {} cluster = 0 - if threshold.has_key("ReplicationTrend"): - threshold_val = threshold["ReplicationTrend"] + print accessor["type"] + if threshold.has_key(accessor["name"]): + threshold_val = threshold[accessor["name"]] else: threshold_val = accessor["threshold"] for bucket, stats_info in stats_buffer.buckets.iteritems(): @@ -113,19 +114,20 @@ def run(self, accessor, scale, threshold=None): else: ratio = 100.0 * replica[1] / active[1] delta = int(replica[1]) - if ratio > threshold_val["percentage"]["high"]: + if accessor["type"] == "percentage" and ratio > threshold_val["percentage"]["high"]: symptom = accessor["symptom"].format(util.pretty_float(ratio), threshold_val["percentage"]["high"]) num_error.append({"node":active[0], "value": symptom}) res.append((active[0], util.pretty_float(ratio) + "%")) - elif delta > threshold_val["number"]["high"]: + print num_error + elif accessor["type"] == "number" and delta > threshold_val["number"]["high"]: symptom = accessor["symptom"].format(util.number_label(delta), util.number_label(threshold_val["number"]["high"])) num_error.append({"node":active[0], "value": symptom}) res.append((active[0], int(delta))) - elif ratio > threshold_val["percentage"]["low"]: + elif accessor["type"] == "percentage" and ratio > threshold_val["percentage"]["low"]: symptom = accessor["symptom"].format(util.pretty_float(ratio), threshold_val["percentage"]["low"]) num_warn.append({"node":active[0], "value": symptom}) res.append((active[0], util.pretty_float(ratio) + "%")) - elif delta > threshold_val["number"]["low"]: + elif accessor["type"] == "number" and delta > threshold_val["number"]["low"]: symptom = accessor["symptom"].format(util.number_label(delta), util.number_label(threshold_val["number"]["low"])) num_warn.append({"node":active[0], "value": symptom}) res.append((active[0], int(delta))) @@ -134,11 +136,11 @@ def run(self, accessor, scale, threshold=None): if active_total > 0: ratio = replica_total * 100.0 / active_total cluster += ratio - if ratio > threshold_val["percentage"]["high"]: + if accessor["type"] == "percentage" and ratio > threshold_val["percentage"]["high"]: symptom = accessor["symptom"].format(util.pretty_float(ratio), threshold_val["percentage"]["high"]) num_error.append({"node":"total", "value": symptom}) res.append(("total", util.pretty_float(ratio) + "%")) - elif ratio > threshold_val["percentage"]["low"]: + elif accessor["type"] == "percentage" and ratio > threshold_val["percentage"]["low"]: symptom = accessor["symptom"].format(util.pretty_float(ratio), threshold_val["percentage"]["low"]) num_warn.append({"node":"total", "value": symptom}) res.append(("total", util.pretty_float(ratio) + "%")) @@ -230,6 +232,7 @@ def run(self, accessor, scale, threshold=None): "counter" : ["curr_items", "ep_tap_total_total_backlog_size"], "scale" : "hour", "code" : "ReplicationTrend", + "type" : "percentage", "threshold" : { "percentage" : { "low" : 10.0, @@ -251,6 +254,7 @@ def run(self, accessor, scale, threshold=None): "counter" : ["curr_items", "ep_tap_total_total_backlog_size"], "scale" : "hour", "code" : "ReplicationTrend", + "type" : "number", "threshold" : { "number" : { "low" : 50000,