Module: check_mk
Branch: master
Commit: ab6113372ffa64ad4968374353db52c94c3d7d9d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ab6113372ffa64…
Author: Óscar Nájera <on(a)mathias-kettner.de>
Date: Fri Apr 5 15:46:08 2019 +0200
RRD data query has configurable limit on data length
RRDtool has a configurable default limit of 400 points per
query. Livestatus did not configure that value until now, but we may need
to do queries over large periods of time and we don't want down sampling.
This change offers backwards compatibility, leaving this parameter as
optional.
The off by one in the query to result arises on the new way result bounds
are given. Now the result bounds contain the query bounds instead of
providing a shift of bounds between query and response.
CMK-1935
Change-Id: I2bcd22396887fe04f7617cb6e1248225662482c1
---
cmk/utils/prediction.py | 8 +++-----
tests/integration/cmk_base/test_services_prediction.py | 10 ++++++++++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/cmk/utils/prediction.py b/cmk/utils/prediction.py
index 8aab80d..c1236af 100644
--- a/cmk/utils/prediction.py
+++ b/cmk/utils/prediction.py
@@ -111,15 +111,13 @@ class TimeSeries(object):
return self.start == other.start and self.end == other.end and self.step ==
other.step and self.values == other.values
-def get_rrd_data(hostname, service_description, varname, cf, fromtime, untiltime):
+def get_rrd_data(hostname, service_description, varname, cf, fromtime, untiltime,
max_entries=400):
"""Fetch RRD historic metrics data of a specific service, within the
specified time range
returns a TimeSeries object holding interval and data information
Query to livestatus always returns if database is found, thus:
- Values can be None when there is no data for a given timestamp
- - Livestatus/rrdtool returns a maximum of 400 data-points per query,
- even if better resolution is available within the time range.
- Reply from livestatus/rrdtool is always enough to describe the
queried interval. That means, the returned bounds are always outside
the queried interval.
@@ -140,11 +138,11 @@ def get_rrd_data(hostname, service_description, varname, cf,
fromtime, untiltime
rpn = "%s.%s" % (varname, cf.lower()) # "MAX" ->
"max"
lql = "GET services\n" \
- "Columns: rrddata:m1:%s:%s:%s:%s\n" \
+ "Columns: rrddata:m1:%s:%s:%s:%s:%s\n" \
"OutputFormat: python\n" \
"Filter: host_name = %s\n" \
"Filter: description = %s\n" % tuple(map(livestatus.lqencode,
- map(str, (rpn, fromtime, untiltime,
step,
+ map(str, (rpn, fromtime, untiltime,
step, max_entries,
hostname,
service_description))))
try:
diff --git a/tests/integration/cmk_base/test_services_prediction.py
b/tests/integration/cmk_base/test_services_prediction.py
index fa6e331..a5a279b 100644
--- a/tests/integration/cmk_base/test_services_prediction.py
+++ b/tests/integration/cmk_base/test_services_prediction.py
@@ -88,6 +88,16 @@ def test_get_rrd_data(cfg_setup, utcdate, timezone, period, result):
assert (timeseries.step, len(timeseries.values)) == result
+(a)pytest.mark.parametrize("max_entriestries, result", [(400, (180, 401)), (20, (3600,
21)),
+ (50, (1800, 41)), (1000, (120, 600)),
+ (1200, (60, 1200))])
+def test_get_rrd_data_point_max(cfg_setup, max_entries, result):
+ from_time, until_time = 1543430040, 1543502040
+ timeseries = cmk.utils.prediction.get_rrd_data('test-prediction', 'CPU
load', 'load15', 'MAX',
+ from_time, until_time, max_entries)
+ assert (timeseries.step, len(timeseries.values)) == result
+
+
@pytest.mark.parametrize('utcdate, timezone, params, reference', [
("2018-09-01 07:00", "Europe/Berlin", {
'period': 'wday',