From 3d128efe07b8fef4ef1910c4532ddf9de8387a32 Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Sat, 14 Mar 2020 09:52:01 +0200 Subject: [PATCH] rrdtool: Take update time as we start updating db Turns out commit 03aa50c69 didn't fix the drifting problem completely. It is still possible that acquiring the data takes arbitrarily long time and we end up inserting the data in the middle of the database update interval, which will cause rrdtool to interpolate the data point with previous or next entry. Fix it by taking the timestamp before we start the update procedure and using that time as we feed in the data. Signed-off-by: Timo Kokkonen --- rrdtool.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rrdtool.c b/rrdtool.c index 6748c39..5b7d3ac 100644 --- a/rrdtool.c +++ b/rrdtool.c @@ -262,7 +262,7 @@ static int run_post_draw_cmd(struct rrd_database *rrd) static int do_rrdtool_update_data(struct rrd_database *rrd) { - char data[RRD_DATA_MAX_LEN + 3]; /* 3 == "N:" + NULL termination */ + char data[RRD_DATA_MAX_LEN + 12]; /* 12 == "%s:" + NULL termination */ char cmd[] = RRDTOOL_CMD; // char cmd[] = "echo"; char *const cmdline[] = { @@ -275,7 +275,7 @@ static int do_rrdtool_update_data(struct rrd_database *rrd) int l; bzero(data, sizeof(data)); - l = sprintf(data, "N:"); + l = sprintf(data, "%zd:", time(NULL)); if (rrd->parser && rrd->parser->parse) { rrd->parser->parse(data + l, rrd->parser_data, -- 2.45.0