fix computation of utilization
Message-ID: <54525f76.WgqKRtu3t7obEOC+%mk(a)mathias-kettner.de>
User-Agent: Heirloom mailx 12.5 6/20/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Module: check_mk
Branch: master
Commit: 511240a111105e316f611849c04524cdfbec67a6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=511240a111105e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Oct 30 16:51:28 2014 +0100
#1478 FIX kernel.util, statgrab_cpu: fix computation of utilization
This was broken due to a recent code restructuration.
---
.werks/1478 | 11 +++++++++++
ChangeLog | 3 +++
checks/cpu_util.include | 15 ++++++++++++---
checks/kernel | 9 +--------
checks/statgrab_cpu | 27 ++++++++++++++-------------
5 files changed, 41 insertions(+), 24 deletions(-)
diff --git a/.werks/1478 b/.werks/1478
new file mode 100644
index 0000000..b2539c1
--- /dev/null
+++ b/.werks/1478
@@ -0,0 +1,11 @@
+Title: kernel.util, statgrab_cpu: fix computation of utilization
+Level: 1
+Component: checks
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.5i7
+Date: 1414684254
+
+This was broken due to a recent code restructuration.
+
diff --git a/ChangeLog b/ChangeLog
index 1fdff2d..9e04b5d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
1.2.5i7:
+ Checks & Agents:
+ * 1478 FIX: kernel.util, statgrab_cpu: fix computation of utilization...
+
Multisite:
* 1164 FIX: Fixed links from servicegroup overviews to single servicegroups
diff --git a/checks/cpu_util.include b/checks/cpu_util.include
index 78fb291..5e680b0 100644
--- a/checks/cpu_util.include
+++ b/checks/cpu_util.include
@@ -77,7 +77,16 @@ def check_cpu_util(util, params, this_time = None):
perfdata += extraperf # reference curve for predictive levels
return state, infotext, perfdata
-# This one can handle user, system and wait
+
+# This one can handle user, system and wait. values is a list of:
+# - 0 - user: normal processes executing in user mode
+# - 1 - nice: niced processes executing in user mode
+# - 2 - system: processes executing in kernel mode
+# - 3 - idle: twiddling thumbs
+# - 4 - iowait: waiting for I/O to complete
+# - 5 - irq: servicing interrupts
+# - 6 - softirq: servicing softirqs
+# - 7 - steal: involuntary wait
def check_cpu_util_unix(values, params):
this_time = int(time.time())
# Compute jiffi-differences of all relevant counters
@@ -96,8 +105,8 @@ def check_cpu_util_unix(values, params):
raise MKCounterWrapped(None, "Too short time difference since last
check")
user = diff_values[0] + diff_values[1] # add user + nice
- system = diff_values[2]
- wait = diff_values[3]
+ system = diff_values[2] + diff_values[5] + diff_values[6]
+ wait = diff_values[4]
user_perc = 100.0 * float(user) / float(sum_jiffies)
system_perc = 100.0 * float(system) / float(sum_jiffies)
wait_perc = 100.0 * float(wait) / float(sum_jiffies)
diff --git a/checks/kernel b/checks/kernel
index e773fee..c7aad00 100644
--- a/checks/kernel
+++ b/checks/kernel
@@ -139,14 +139,7 @@ def kernel_check_cpu_utilization(item, params, info):
# 'cpu' user nice system idle wait hw-int sw-int (steal ...)
# convert number to int
values = [ int(x) for x in line[1:8] ]
- user = values[0]
- nice = values[1]
- system = values[2]
- wait = values[4]
- hw_int = values[5]
- sw_int = values[6]
- idle = 100 - user - system - nice - wait
- return check_cpu_util_unix([user, nice, system, wait, hw_int, sw_int, idle], params)
+ return check_cpu_util_unix(values, params)
check_info["kernel.util"] = {
'check_function': kernel_check_cpu_utilization,
diff --git a/checks/statgrab_cpu b/checks/statgrab_cpu
index 64012b3..84ca0a7 100644
--- a/checks/statgrab_cpu
+++ b/checks/statgrab_cpu
@@ -27,8 +27,9 @@
def inventory_statgrab_cpu(info):
- if len(info) > 1:
- return [(None, {})]
+ print info
+ if len(info) > 1:
+ return [(None, {})]
def check_statgrab_cpu(item, params, info):
@@ -37,19 +38,19 @@ def check_statgrab_cpu(item, params, info):
user = 0
nice = 0
for var, value in info:
- if var == 'iowait':
- wait = int(value)
- elif var == 'kernel':
- system = int(value)
+ if var == 'user':
+ user = int(value)
elif var == 'nice':
nice = int(value)
- elif var == 'user':
- user = int(value)
- elif var == 'total':
- total = int(value)
- idle = 100 - total
- # user, nice, system, wait, hw-int, sw-int, idle
- values = [ user, nice, system, wait, 0, 0, idle ]
+ elif var == 'kernel':
+ system = int(value)
+ elif var == 'idle':
+ idle = int(value)
+ elif var == 'iowait':
+ wait = int(value)
+
+ # user, nice, system, idle, iowait, hw-int, sw-int, steal
+ values = [ user, nice, system, idle, wait, 0, 0, 0 ]
# No return cause of the use of yield
return check_cpu_util_unix(values, params)