From: Peter Stamfest Date: Sun, 24 Aug 2014 21:19:32 +0000 (+0200) Subject: take start time from sources if unspecified X-Git-Tag: v1.5.0-rc1~42^2~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=efe10d95f8d792e375705eded5cb35ed860dee43;p=thirdparty%2Frrdtool-1.x.git take start time from sources if unspecified --- diff --git a/src/rrd_create.c b/src/rrd_create.c index 9defc5d8..78e554b9 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -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); } diff --git a/tests/Makefile.am b/tests/Makefile.am index 4a8187f2..96488b12 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 \ diff --git a/tests/create-with-source-2 b/tests/create-with-source-2 index 27d5d5ad..6441bc93 100755 --- a/tests/create-with-source-2 +++ b/tests/create-with-source-2 @@ -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 index 00000000..661838e0 --- /dev/null +++ b/tests/create-with-source-3 @@ -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 { + +#- 1010 +#- 4.0400000000e+04 +#- 0 +#+ U +#+ 0.0000000000e+00 +#+ 40 + + + perl -n -e '$a=join("",<>); $a=~s,<(cdp_prep|last_ds|value|unknown_sec).*?,,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