Skip to content

Commit

Permalink
Avoid to apply same method twice
Browse files Browse the repository at this point in the history
  • Loading branch information
bcui6611 committed Aug 24, 2012
1 parent 321fbce commit 1d78356
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions diskqueue_stats.py
Expand Up @@ -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():
Expand Down Expand Up @@ -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)))
Expand All @@ -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) + "%"))
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit 1d78356

Please sign in to comment.