From 03aa50c69d38991d74ae341e18209f0c1344703c Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sun, 25 Aug 2019 15:30:58 +0300 Subject: [PATCH] rrdtool: Stop update times from drifting With rrdtool, database updates should rather take place evenly at the beginning of each update interval. If it happens at random places within the interval, rrdtool will try to interpolate the data to make it "fit better" within the data points. This causes unexpected data values to be generated into the database. Make each updates happen consitently at the beginning of the window to ensure the graphs contain as good raw samples as possible. Signed-off-by: Timo Kokkonen --- rrdtool.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rrdtool.c b/rrdtool.c index c92dee1..6748c39 100644 --- a/rrdtool.c +++ b/rrdtool.c @@ -315,7 +315,13 @@ static int do_rrdtool_update_data(struct rrd_database *rrd) int rrdtool_update_data(struct rrd_database *rrd) { - rrd->last_update = time(0); + time_t now = time(0); + + /* + * This will put our last update slightly into past, but + * ensures our update interval will not drift over time. + */ + rrd->last_update = now - now % rrd->interval; return queue_work(WORK_PRIORITY_HIGH, "rrdtool_update_data", (work_fn_t *)do_rrdtool_update_data, rrd); -- 2.44.0