]> git.itanic.dy.fi Git - rrdd/commitdiff
rrdtool: Use the same timestamp with rrdtool and with logs
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 30 Sep 2020 17:15:15 +0000 (20:15 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 30 Sep 2020 17:15:15 +0000 (20:15 +0300)
Acquiring the data and updating rrdtool database takes some time. Use
the same timestamp for both so that the times are consistent.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
rrdtool.c

index e347400063222f784b8bb6455c0b81353b0711c7..658513be69b309a1e4e017ccacb42cfa7dc396bf 100644 (file)
--- a/rrdtool.c
+++ b/rrdtool.c
@@ -196,9 +196,8 @@ static int sanitize_rrd_update_data(char *data)
        return entries;
 }
 
        return entries;
 }
 
-static int write_to_logfile(struct rrd_database *rrd, const char *data)
+static int write_to_logfile(struct rrd_database *rrd, const char *data, time_t now)
 {
 {
-       time_t t = time(NULL);
        int fd, ret;
        int spacing, i;
        char filename[1024];
        int fd, ret;
        int spacing, i;
        char filename[1024];
@@ -212,7 +211,7 @@ static int write_to_logfile(struct rrd_database *rrd, const char *data)
        if (rrd->logfile_timestamp_fmt)
                time_stamp_fmt = rrd->logfile_timestamp_fmt;
 
        if (rrd->logfile_timestamp_fmt)
                time_stamp_fmt = rrd->logfile_timestamp_fmt;
 
-       strftime(filename, sizeof(filename), rrd->logfile, localtime(&t));
+       strftime(filename, sizeof(filename), rrd->logfile, localtime(&now));
 
        fd = open(filename, O_RDWR | O_APPEND | O_CREAT | O_CLOEXEC, 0644);
        if (fd < 0) {
 
        fd = open(filename, O_RDWR | O_APPEND | O_CREAT | O_CLOEXEC, 0644);
        if (fd < 0) {
@@ -220,7 +219,7 @@ static int write_to_logfile(struct rrd_database *rrd, const char *data)
                return -1;
        }
 
                return -1;
        }
 
-       strftime(logstr, sizeof(logstr), time_stamp_fmt, localtime(&t));
+       strftime(logstr, sizeof(logstr), time_stamp_fmt, localtime(&now));
 
        str_ptr = logstr + strlen(logstr);
 
 
        str_ptr = logstr + strlen(logstr);
 
@@ -279,9 +278,10 @@ static int do_rrdtool_update_data(struct rrd_database *rrd)
                0
        };
        int l;
                0
        };
        int l;
+       time_t now = time(NULL);
 
        bzero(data, sizeof(data));
 
        bzero(data, sizeof(data));
-       l = sprintf(data, "%zd:", time(NULL));
+       l = sprintf(data, "%zd:", now);
 
        if (rrd->parser && rrd->parser->parse) {
                rrd->parser->parse(data + l, rrd->parser_data,
 
        if (rrd->parser && rrd->parser->parse) {
                rrd->parser->parse(data + l, rrd->parser_data,
@@ -291,7 +291,7 @@ static int do_rrdtool_update_data(struct rrd_database *rrd)
                pr_info("Data: %s\n", data);
 
                sanitize_rrd_update_data(data + l);
                pr_info("Data: %s\n", data);
 
                sanitize_rrd_update_data(data + l);
-               write_to_logfile(rrd, data);
+               write_to_logfile(rrd, data, now);
 
                run(cmd, cmdline);
        }
 
                run(cmd, cmdline);
        }