]> git.itanic.dy.fi Git - rrdd/commitdiff
rrdtool: Take update time as we start updating db
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 14 Mar 2020 07:52:01 +0000 (09:52 +0200)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Sat, 14 Mar 2020 07:52:01 +0000 (09:52 +0200)
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 <timo.t.kokkonen@iki.fi>
rrdtool.c

index 6748c39af5c937dced74c00f1fe6c1f128074bb4..5b7d3acebf064f8d51d2d70e7d6767274215ed70 100644 (file)
--- 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,