Module: check_mk
Branch: master
Commit: fcc8fceb0e9c98ed0f074ac6850d3b659573757a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fcc8fceb0e9c98…
Author: Bastian Kuhn <bk(a)mathias-kettner.de>
Date: Mon Mar 30 13:33:48 2015 +0200
check_cpu_peaks: improvements from goetz
---
doc/treasures/active_checks/check_cpu_peaks | 67 ++++++++++++++++-----------
1 file changed, 40 insertions(+), 27 deletions(-)
diff --git a/doc/treasures/active_checks/check_cpu_peaks
b/doc/treasures/active_checks/check_cpu_peaks
index 6e123b0..f2930d8 100755
--- a/doc/treasures/active_checks/check_cpu_peaks
+++ b/doc/treasures/active_checks/check_cpu_peaks
@@ -110,7 +110,8 @@ try:
data = get_rrd_data(host, "CPU utilization", "util",
"MAX", fromtime, untiltime)
datasets.append(data[1])
step_secs = data[0]
- util_total = [ x for x in datasets[0] if x != None ]
+ #util_total = [ x for x in datasets[0] if x != None ]
+ util_total = [ x for x in datasets[0] ]
except Exception, e:
if opt_debug:
raise
@@ -120,40 +121,52 @@ try:
data = get_rrd_data(host, "CPU utilization", key, "MAX",
fromtime, untiltime)
datasets.append(data[1])
step_secs = data[0]
- util_total = map(lambda x: int(sum([y for y in x if y != None])),
- zip(datasets[0], datasets[1], datasets[2]))
- cpu_peak = max(util_total)
+ def sumsum(x):
+ if None in x:
+ return None
+ return int(sum([y for y in x]))
+
+ #util_total = map(lambda x: int(sum([y for y in x if y != None])),
+ util_total = map(sumsum, zip(datasets[0], datasets[1], datasets[2]))
+ cpu_peak = max(util_total)
peak_time = time.localtime(fromtime + step_secs * util_total.index(cpu_peak))
if opt_verbose:
- for idx, x in enumerate(datasets[0]):
- sys.stdout.write("idx: %d " % idx)
- sys.stdout.write("%s\t" % int(datasets[0][idx] or -1))
- sys.stdout.write("%s\t" % int(datasets[1][idx] or -1))
- sys.stdout.write("%s" % int(datasets[2][idx] or -1))
- print ""
+ for idx, x in enumerate(datasets[0]):
+ sys.stdout.write("idx: %d " % idx)
+ sys.stdout.write("%s\t" % int(datasets[0][idx] or -1))
+ sys.stdout.write("%s\t" % int(datasets[1][idx] or -1))
+ sys.stdout.write("%s" % int(datasets[2][idx] or -1))
+ print ""
if is_windows:
- info = [ "CPU utilization from %s until %s" %\
- (time.strftime("%b %d %H:%M:%S", time.localtime(fromtime)),
- time.strftime("%b %d %H:%M:%S", time.localtime(untiltime))) ]
+ info = [ "CPU utilization from %s until %s" %\
+ (time.strftime("%b %d %H:%M:%S", time.localtime(fromtime)),
+ time.strftime("%b %d %H:%M:%S", time.localtime(untiltime))) ]
+ else:
+ info = [ "CPU utilization (user, system, wait) from %s until %s" %\
+ (time.strftime("%b %d %H:%M:%S", time.localtime(fromtime)),
+ time.strftime("%b %d %H:%M:%S", time.localtime(untiltime))) ]
+
+ if cpu_peak:
+ info.append("Highest Peak of %d%% at %s" % (cpu_peak,
time.strftime("%b %d %H:%M:%S", peak_time)))
+ state = 0
+ if crit_level and cpu_peak <= crit_level:
+ info.append("less than %d (!!)" % crit_level)
+ state = 2
+ elif warn_level and cpu_peak <= warn_level:
+ info.append("less than %d (!)" % warn_level)
+ state = 1
+ print ", ".join(info)
+ sys.exit(state)
else:
- info = [ "CPU utilization (user, system, wait) from %s until %s" %\
- (time.strftime("%b %d %H:%M:%S", time.localtime(fromtime)),
- time.strftime("%b %d %H:%M:%S", time.localtime(untiltime))) ]
-
- info.append("Highest Peak of %d%% at %s" % (cpu_peak,
time.strftime("%b %d %H:%M:%S", peak_time)))
- state = 0
- if crit_level and cpu_peak <= crit_level:
- info.append("less than %d (!!)" % crit_level)
- state = 2
- elif warn_level and cpu_peak <= warn_level:
- info.append("less than %d (!)" % warn_level)
- state = 1
- print ", ".join(info)
- sys.exit(state)
+ info.append("No data available in time period")
+ state = 0
+ print ": ".join(info)
+ sys.exit(state)
+
except MKGeneralException, e:
if opt_debug: