Module: check_mk
Branch: master
Commit: 209639ca739776749a0a7c69ac8c54e8a3c269ee
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=209639ca739776…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Oct 14 13:11:32 2014 +0200
#1078 FIX Fix compensation for daylight safing time in prediction
---
.werks/1078 | 9 ++++++++
ChangeLog | 1 +
modules/prediction.py | 54 ++++++++++++++++++++++++++++++----------------
web/htdocs/prediction.py | 8 +++++--
4 files changed, 52 insertions(+), 20 deletions(-)
diff --git a/.werks/1078 b/.werks/1078
new file mode 100644
index 0000000..a5bf6bf
--- /dev/null
+++ b/.werks/1078
@@ -0,0 +1,9 @@
+Title: Fix compensation for daylight safing time in prediction
+Level: 2
+Component: checks
+Compatible: compat
+Version: 1.2.5i6
+Date: 1413285066
+Class: fix
+
+
diff --git a/ChangeLog b/ChangeLog
index 0fd0eaa..b6584a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -104,6 +104,7 @@
* 1122 FIX: windows agent: unicode logfile monitoring: now able to detect incomplete
written lines...
* 1184 FIX: cisco_power: Fixed detection of item. In some cases the status
information was part of the item...
NOTE: Please refer to the migration notes!
+ * 1078 FIX: Fix compensation for daylight safing time in prediction
Multisite:
* 1066 Implemented Dashboard Designer...
diff --git a/modules/prediction.py b/modules/prediction.py
index 238a70d..fdfe641 100644
--- a/modules/prediction.py
+++ b/modules/prediction.py
@@ -113,42 +113,54 @@ def get_rrd_data(hostname, service_description, varname, cf,
fromtime, untiltime
daynames = [ "monday", "tuesday", "wednesday",
"thursday",
"friday", "saturday", "sunday"]
+# Check wether a certain time stamp lies with in daylight safing time (DST)
+def is_dst(timestamp):
+ return time.localtime(timestamp).tm_isdst
+
+# Returns the timezone *including* DST shift at a certain point of time
+def timezone_at(timestamp):
+ if is_dst(timestamp):
+ return time.altzone
+ else:
+ return time.timezone
+
def group_by_wday(t):
wday = time.localtime(t).tm_wday
- day_of_epoch, rel_time = divmod(t - time.timezone, 86400)
+ day_of_epoch, rel_time = divmod(t - timezone_at(t), 86400)
return daynames[wday], rel_time
def group_by_day(t):
- return "everyday", (t - time.timezone) % 86400
+ return "everyday", (t - timezone_at(t)) % 86400
def group_by_day_of_month(t):
broken = time.localtime(t)
mday = broken[2]
- return str(mday), (t - time.timezone) % 86400
+ return str(mday), (t - timezone_at(t)) % 86400
def group_by_everyhour(t):
- return "everyhour", (t - time.timezone) % 3600
+ return "everyhour", (t - timezone_at(t)) % 3600
+
prediction_periods = {
"wday" : {
- "slice" : 86400, # 7 slices
- "groupby" : group_by_wday,
- "valid" : 7,
+ "slice" : 86400, # 7 slices
+ "groupby" : group_by_wday,
+ "valid" : 7,
},
"day" : {
- "slice" : 86400, # 31 slices
- "groupby" : group_by_day_of_month,
- "valid" : 28,
+ "slice" : 86400, # 31 slices
+ "groupby" : group_by_day_of_month,
+ "valid" : 28,
},
"hour" : {
- "slice" : 86400, # 1 slice
- "groupby" : group_by_day,
- "valid" : 1,
+ "slice" : 86400, # 1 slice
+ "groupby" : group_by_day,
+ "valid" : 1,
},
"minute" : {
- "slice" : 3600, # 1 slice
- "groupby" : group_by_everyhour,
- "valid" : 24,
+ "slice" : 3600, # 1 slice
+ "groupby" : group_by_everyhour,
+ "valid" : 24,
},
}
@@ -168,10 +180,16 @@ def compute_prediction(pred_file, timegroup, params, period_info,
from_time, dsn
begin = from_time
slices = []
absolute_begin = from_time - params["horizon"] * 86400
- # The resolution of the different time ranges differs. We interpolate
+
+ # The resolutions of the different time ranges differ. We interpolate
# to the best resolution. We assume that the youngest slice has the
- # finest resolution. We also assume, that step step is always dividable
+ # finest resolution. We also assume, that each step is always dividable
# by the smallest step.
+
+ # Note: due to the f**king DST, we can have several shifts between
+ # DST and non-DST during are computation. We need to compensate for
+ # those. DST swaps within slices are being ignored. The DST flag
+ # is checked against the beginning of the slice.
smallest_step = None
while begin >= absolute_begin:
tg, fr, un, rel = get_prediction_timegroup(begin, period_info)
diff --git a/web/htdocs/prediction.py b/web/htdocs/prediction.py
index e35238f..1cda8d8 100644
--- a/web/htdocs/prediction.py
+++ b/web/htdocs/prediction.py
@@ -140,9 +140,13 @@ def page_graph():
if now >= from_time and now <= until_time:
rrd_step, rrd_data = get_rrd_data(host, service, dsname, "MAX",
from_time, until_time)
render_curve(rrd_data, "#0000ff", 2)
-
+ if time.daylight:
+ tz_offset = time.altzone
+ else:
+ tz_offset = time.timezone
if current_value != None:
- rel_time = (time.time() - time.timezone) % timegroup["slice"]
+ html.debug(now, tz_offset, timegroup["slice"])
+ rel_time = (now - tz_offset) % timegroup["slice"]
render_point(timegroup["range"][0] + rel_time, current_value,
"#0000ff")
html.footer()