Beautifying many debug messages..
[collectd.git] / src / rrdtool.c
index d20a814..8ad0106 100644 (file)
@@ -283,7 +283,7 @@ static int ds_get (char ***ret, const data_set_t *ds)
        return (ds_num);
 }
 
-static int rrd_create_file (char *filename, const data_set_t *ds)
+static int rrd_create_file (char *filename, const data_set_t *ds, const value_list_t *vl)
 {
        char **argv;
        int argc;
@@ -293,6 +293,7 @@ static int rrd_create_file (char *filename, const data_set_t *ds)
        int ds_num;
        int i, j;
        char stepsize_str[16];
+       char begin_str[16];
        int status = 0;
 
        if (check_create_dir (filename))
@@ -310,7 +311,7 @@ static int rrd_create_file (char *filename, const data_set_t *ds)
                return (-1);
        }
 
-       argc = ds_num + rra_num + 4;
+       argc = ds_num + rra_num + 6;
 
        if ((argv = (char **) malloc (sizeof (char *) * (argc + 1))) == NULL)
        {
@@ -328,12 +329,23 @@ static int rrd_create_file (char *filename, const data_set_t *ds)
                return (-1);
        }
 
+       assert (vl->time > 10);
+       status = snprintf (begin_str, sizeof (begin_str),
+                       "%llu", (unsigned long long) (vl->time - 10));
+       if ((status < 1) || (status >= sizeof (begin_str)))
+       {
+               ERROR ("rrdtool plugin: snprintf failed.");
+               return (-1);
+       }
+
        argv[0] = "create";
        argv[1] = filename;
-       argv[2] = "-s";
-       argv[3] = stepsize_str;
+       argv[2] = "-b";
+       argv[3] = begin_str;
+       argv[4] = "-s";
+       argv[5] = stepsize_str;
 
-       j = 4;
+       j = 6;
        for (i = 0; i < ds_num; i++)
                argv[j++] = ds_def[i];
        for (i = 0; i < rra_num; i++)
@@ -582,7 +594,7 @@ static void rrd_cache_flush (int timeout)
        if (cache == NULL)
                return;
 
-       DEBUG ("Flushing cache, timeout = %i", timeout);
+       DEBUG ("rrdtool plugin: Flushing cache, timeout = %i", timeout);
 
        now = time (NULL);
 
@@ -615,7 +627,7 @@ static void rrd_cache_flush (int timeout)
        {
                if (avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0)
                {
-                       DEBUG ("avl_remove (%s) failed.", keys[i]);
+                       DEBUG ("rrdtool plugin: avl_remove (%s) failed.", keys[i]);
                        continue;
                }
 
@@ -627,7 +639,6 @@ static void rrd_cache_flush (int timeout)
        } /* for (i = 0..keys_num) */
 
        free (keys);
-       DEBUG ("Flushed %i value(s)", keys_num);
 
        cache_flush_last = now;
 } /* void rrd_cache_flush */
@@ -650,7 +661,7 @@ static int rrd_write (const data_set_t *ds, const value_list_t *vl)
        {
                if (errno == ENOENT)
                {
-                       if (rrd_create_file (filename, ds))
+                       if (rrd_create_file (filename, ds, vl))
                                return (-1);
                }
                else