]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
take start time from sources if unspecified
authorPeter Stamfest <peter@stamfest.at>
Sun, 24 Aug 2014 21:19:32 +0000 (23:19 +0200)
committerPeter Stamfest <peter@stamfest.at>
Sun, 31 Aug 2014 20:19:22 +0000 (22:19 +0200)
src/rrd_create.c
tests/Makefile.am
tests/create-with-source-2
tests/create-with-source-3 [new file with mode: 0755]

index 9defc5d8fc5da8e0e8b9904506831943e5d2d7b9..78e554b9b63c2c0659b78b10fa5c981266a8c0da 100644 (file)
@@ -54,7 +54,7 @@ int rrd_create(
     };
     int       option_index = 0;
     int       opt;
-    time_t    last_up = time(NULL) - 10;
+    time_t    last_up = -1;
     unsigned long pdp_step = 300;
     rrd_time_value_t last_up_tv;
     const char *parsetime_error = NULL;
@@ -644,7 +644,7 @@ int rrd_create_r2(
     rrd.ds_def = NULL;
     rrd.rra_def = NULL;
 
-    rrd.live_head->last_up = last_up;
+    rrd.live_head->last_up = last_up > 0 ? last_up : time(NULL) - 10;
 
     /* optind points to the first non-option command line arg,
      * in this case, the file name. */
@@ -724,6 +724,8 @@ int rrd_create_r2(
     if (rc != 0) goto done;
 
     if (sources != NULL) {
+        time_t    sources_latest_last_up = 0;
+
         for (const char **s = sources ; *s ; s++) {
             rrd_t *srrd = malloc(sizeof(rrd_t));
             if (srrd == NULL) {
@@ -735,6 +737,7 @@ int rrd_create_r2(
             rrd_file_t *sf = rrd_open(*s, srrd, RRD_READONLY | RRD_READAHEAD | RRD_READVALUES);
 
             if (sf == NULL) {
+                rrd_set_error("Cannot open source RRD %s", *s);
                 goto done;
             }
             sources_rrd_files = g_list_append(sources_rrd_files, sf);
@@ -742,8 +745,13 @@ int rrd_create_r2(
                 rrd_set_error("Cannot keep information about just opened source RRD - likely leaking resources!");
                 goto done;
             }
+            
+            sources_latest_last_up = max(sources_latest_last_up, sf->rrd->live_head->last_up);
+        }
+    
+        if (last_up == -1) {
+            rrd.live_head->last_up = sources_latest_last_up;
         }
-        
         rrd_prefill_data(&rrd, sources_rrd_files);
     }
     
index 4a8187f275166f98ea31f99788df12f742a45a83..96488b12f5625f4fc8d1bab2a93e605a4390c5c6 100644 (file)
@@ -2,7 +2,7 @@ TESTS = modify1 modify2 modify3 modify4 modify5 \
        tune1 tune2 rpn1 \
        rrdcreate \
        dump-restore \
-       create-with-source-1 create-with-source-2
+       create-with-source-1 create-with-source-2 create-with-source-3
 EXTRA_DIST = Makefile.am \
        alltests functions \
        modify1 modify-test1.create.dump modify-test1.mod1.dump \
index 27d5d5ad48cb7e011c594ebebd1d6f2f1c83fa70..6441bc93b3296e23cbb1c94ab37ed52151eb6606 100755 (executable)
@@ -83,3 +83,11 @@ $RRDTOOL dump ${PREFIX}bca2.rrd | xmlfilter > ${PREFIX}bca2.xml
 $DIFF ${PREFIX}bca1.xml ${PREFIX}bca2.xml
 report data-match-bca
 
+$RRDTOOL create ${PREFIX}bca3.rrd --step 60 --source ${PREFIX}a1.rrd --source ${PREFIX}b1.rrd DS:b:GAUGE:120:0:U DS:c:GAUGE:120:0:U DS:a:GAUGE:120:0:U RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 
+report create-bac-with-two-sources-no-start
+
+$RRDTOOL dump ${PREFIX}bca3.rrd | xmlfilter > ${PREFIX}bca3.xml
+$DIFF ${PREFIX}bca1.xml ${PREFIX}bca3.xml
+report data-match-bca-no-start
+
+rm -f ${PREFIX}*.rrd ${PREFIX}*.xml
diff --git a/tests/create-with-source-3 b/tests/create-with-source-3
new file mode 100755 (executable)
index 0000000..661838e
--- /dev/null
@@ -0,0 +1,120 @@
+#!/bin/bash
+
+. $(dirname $0)/functions
+
+BASE=$BASEDIR/$(basename $0)-test
+PREFIX=$BUILDDIR/$(basename $0)-test
+
+# currently, we do not properly copy cdp and pdp information, so for
+# comparison of RRD dumps, we just filter out those parts we do not
+# expect to match anyway...
+function xmlfilter {
+
+#-               <last_ds>1010</last_ds>
+#-               <value>4.0400000000e+04</value>
+#-               <unknown_sec> 0 </unknown_sec>
+#+               <last_ds>U</last_ds>
+#+               <value>0.0000000000e+00</value>
+#+               <unknown_sec> 40 </unknown_sec>
+
+
+       perl -n -e '$a=join("",<>); $a=~s,<(cdp_prep|last_ds|value|unknown_sec).*?</\1>,,msg ; print $a'
+}
+
+
+ST=1300000000
+
+
+rm -f ${PREFIX}*.rrd ${PREFIX}*.xml
+$RRDTOOL create ${PREFIX}a1_x.rrd --start $(($ST-1)) --step 60 DS:a:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 
+report createa1
+
+$RRDTOOL create ${PREFIX}b1_x.rrd --start $(($ST-1)) --step 60 DS:b:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 
+report createb1
+
+$RRDTOOL create ${PREFIX}ab1_x.rrd --start $(($ST-1)) --step 60 DS:a:GAUGE:120:0:U DS:b:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 
+report createab1
+
+$RRDTOOL create ${PREFIX}ba1_x.rrd --start $(($ST-1)) --step 60 DS:b:GAUGE:120:0:U DS:a:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 
+report createba1
+
+$RRDTOOL create ${PREFIX}bca1_x.rrd --start $(($ST-1)) --step 60 DS:b:GAUGE:120:0:U DS:c:GAUGE:120:0:U DS:a:GAUGE:120:0:U  RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2 
+report createbca1
+
+for A in ${PREFIX}*_x.rrd ; do
+       cp $A $(basename $A _x.rrd)_y.rrd
+done
+
+
+UPDATEA_x=
+UPDATEB_x=
+UPDATEAB_x=
+V=10
+for A in $(seq $ST 60 $(($ST + 3000)) ) ; do
+       UPDATEA_x="$UPDATEA_x $A:$V"
+       UPDATEB_x="$UPDATEB_x $A:$(($V * 2))"
+       UPDATEAB_x="$UPDATEAB_x $A:$V:$(($V * 2))"
+       V=$(($V + 20))
+       ST=$A
+done
+
+ST_X=$ST
+
+# add a gap
+ST=$((ST+1200))
+
+UPDATEA_y=
+UPDATEB_y=
+UPDATEAB_y=
+V=40
+for A in $(seq $ST 60 $(($ST + 3000)) ) ; do
+       UPDATEA_y="$UPDATEA_y $A:$V"
+       UPDATEB_y="$UPDATEB_y $A:$(($V * 2))"
+       UPDATEAB_y="$UPDATEAB_y $A:$V:$(($V * 2))"
+       V=$(($V + 50))
+       ST=$A
+done
+
+ST_Y=$ST
+
+
+
+$RRDTOOL update ${PREFIX}a1_x.rrd  $UPDATEA_x
+$RRDTOOL update ${PREFIX}b1_x.rrd  $UPDATEB_x
+$RRDTOOL update ${PREFIX}ab1_x.rrd $UPDATEAB_x
+$RRDTOOL update ${PREFIX}ba1_x.rrd --template a:b $UPDATEAB_x
+$RRDTOOL update ${PREFIX}bca1_x.rrd --template a:b $UPDATEAB_x
+
+$RRDTOOL update ${PREFIX}a1_y.rrd  $UPDATEA_y
+$RRDTOOL update ${PREFIX}b1_y.rrd  $UPDATEB_y
+$RRDTOOL update ${PREFIX}ab1_y.rrd $UPDATEAB_y
+$RRDTOOL update ${PREFIX}ba1_y.rrd --template a:b $UPDATEAB_y
+$RRDTOOL update ${PREFIX}bca1_y.rrd --template a:b $UPDATEAB_y
+
+
+
+
+$RRDTOOL create ${PREFIX}ab2_xy.rrd --start $ST --step 60 --source ${PREFIX}a1_x.rrd --source ${PREFIX}b1_x.rrd --source ${PREFIX}a1_y.rrd --source ${PREFIX}b1_y.rrd DS:a:GAUGE:120:0:U DS:b:GAUGE:120:0:U RRA:AVERAGE:0.5:1:400 RRA:AVERAGE:0.5:5:8 RRA:MIN:0.5:5:8 RRA:MAX:0.5:5:8 RRA:LAST:0.5:5:8 
+report create-ab-with-four-sources
+
+
+# now re-extract single value RRDs from the combined one....
+
+
+$RRDTOOL create ${PREFIX}a2_x.rrd --start $ST_X --step 60 --source ${PREFIX}ab2_xy.rrd DS:a:GAUGE:120:0:U RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2
+report recreate-original-a1_x-from-combined-source
+
+$RRDTOOL dump ${PREFIX}a1_x.rrd | xmlfilter > ${PREFIX}a1_x.xml
+$RRDTOOL dump ${PREFIX}a2_x.rrd | xmlfilter > ${PREFIX}a2_x.xml
+$DIFF ${PREFIX}a1_x.xml ${PREFIX}a2_x.xml
+report data-match-a1_x
+
+$RRDTOOL create ${PREFIX}b2_x.rrd --start $ST_X --step 60 --source ${PREFIX}ab2_xy.rrd DS:b:GAUGE:120:0:U RRA:AVERAGE:0.5:1:100 RRA:AVERAGE:0.5:5:2 RRA:MIN:0.5:5:2 RRA:MAX:0.5:5:2 RRA:LAST:0.5:5:2
+report recreate-original-b1_x-from-combined-source
+
+$RRDTOOL dump ${PREFIX}b1_x.rrd | xmlfilter > ${PREFIX}b1_x.xml
+$RRDTOOL dump ${PREFIX}b2_x.rrd | xmlfilter > ${PREFIX}b2_x.xml
+$DIFF ${PREFIX}b1_x.xml ${PREFIX}b2_x.xml
+report data-match-b1_x
+
+rm -f ${PREFIX}*.rrd ${PREFIX}*.xml