Module: check_mk
Branch: master
Commit: ed838a78f64ae4c40f0384b06cdf86fa8380d8f0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ed838a78f64ae4…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Mar 17 13:44:07 2011 +0100
FIX: fix computation of weight when averaging
---
ChangeLog | 1 +
checks/df.include | 2 +-
checks/diskstat | 2 +-
checks/if.include | 2 +-
modules/check_mk_base.py | 18 ++++++++++++++++--
5 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a368655..33adf6a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
1.1.11i1:
Core, Setup, etc.:
+ * FIX: fix computation of weight when averaging
* SNMP scan functions can now call oid(".1.3.6.1.4.1.9.9.13.1.3.1.3.*")
That will return the *first* OID beginning with .1.3.6.1.4.1.9.9.13.1.3.1.3
* New config option: Set check_submission = "file" in order to write
diff --git a/checks/df.include b/checks/df.include
index fd5edea..01d0b22 100644
--- a/checks/df.include
+++ b/checks/df.include
@@ -163,7 +163,7 @@ def df_check_filesystem(hostname, mountpoint, size_mb, avail_mb,
params):
if levels.get("trend_perfdata"):
perfdata.append(("growth", rate * range_sec))
# average trend, initialize with zero
- timedif, rate_avg = get_average("df.%s.trend" % mountpoint,
this_time, rate, range_sec, True)
+ timedif, rate_avg = get_average("df.%s.trend" % mountpoint,
this_time, rate, range_sec / 60.0, True)
# rate_avg is groth in MB/sec
trend = rate_avg * range_sec
diff --git a/checks/diskstat b/checks/diskstat
index 7324ef7..cf9e03e 100644
--- a/checks/diskstat
+++ b/checks/diskstat
@@ -91,7 +91,7 @@ def check_diskstat_line(this_time, item, params, line):
# compute average of the rate over ___ minutes
if average_range != None:
- timedif, avg = get_average(countername + ".avg", this_time,
bytes_per_sec, average_range * 60)
+ timedif, avg = get_average(countername + ".avg", this_time,
bytes_per_sec, average_range)
perfdata.append( (what + ".avg", avg) )
bytes_per_sec = avg
diff --git a/checks/if.include b/checks/if.include
index 223051d..358e650 100644
--- a/checks/if.include
+++ b/checks/if.include
@@ -212,7 +212,7 @@ def check_if_common(item, params, info):
# handle computation of average
if average:
- timedif, traffic_avg = get_average("if.%s.%s.avg" %
(what, item), this_time, traffic, average * 60)
+ timedif, traffic_avg = get_average("if.%s.%s.avg" %
(what, item), this_time, traffic, average)
infotext += ", %dmin avg: %s/s" % (average,
get_bytes_human_readable(traffic_avg))
perfdata.append( ("%s_avg_%d" % (what, average),
traffic_avg, bw_warn, bw_crit, 0, ref_speed) )
traffic = traffic_avg # apply levels to average traffic
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 0cdfa75..9667140 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -651,10 +651,24 @@ def get_average(itemname, this_time, this_val, backlog,
initialize_zero = True):
last_time, last_val = g_counters.get(itemname)
timedif = this_time - last_time
- # compute weight, but how?
- weight = math.e ** (-timedif / backlog)
+ # Compute the weight: We do it like this: First we assume that
+ # we get one sample per minute. And that backlog is the number
+ # of minutes we should average over. Then we want that the weight
+ # of the values of the last average minutes have a fraction of W%
+ # in the result and the rest until infinity the rest (1-W%).
+ # Then the weight can be computed as backlog'th root of 1-W
+ percentile = 0.50
+
+ weight_per_minute = (1 - percentile) ** (1.0 / backlog)
+
+ # now let's compute the weight per second. This is done
+ weight = weight_per_minute ** (timedif / 60.0)
new_val = last_val * weight + this_val * (1 - weight)
+
+ # print "Alt: %.5f, Jetzt: %.5f, Timedif: %.1f, Gewicht: %.5f, Neu: %.5f" %
\
+ # (last_val, this_val, timedif, weight, new_val)
+
g_counters[itemname] = (this_time, new_val)
return timedif, new_val