Code

1) Sigma calculation had an error. The first data value in each bin didn't get squared.
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Tue, 21 Dec 2010 16:38:48 +0000 (16:38 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Tue, 21 Dec 2010 16:38:48 +0000 (16:38 +0000)
2) "rrdfillmissing" was dummy. I have added code to do the work. The parameter has NOW to be in seconds. In doc it is
given in steps. The size of steps depends to much on size of graph so I think its easier to use seconds and internal
calculate the number of steps.

by Hans Jørgen Jakobsen

git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk/program@2155 a5681a0c-68f1-0310-ab6d-d61299d08faa

NEWS
doc/rrdgraph_libdbi.pod
src/rrd_fetch_libdbi.c

diff --git a/NEWS b/NEWS
index 0c593af414d457e89fbd4d5a0de3a6b48011a3a5..8a48192af00a43722022661f88ccfb70784bfac2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -27,6 +27,11 @@ API
 ---
 * exported rrd_update_v_r for theadsave rrd_update calls
 
 ---
 * exported rrd_update_v_r for theadsave rrd_update calls
 
+libDBI
+------
+* make rrdfillmissing actually work. The parameter is now in seconds and not
+  in steps for ease of use by Hans Jørgen Jakobsen
+
 Bindings
 --------
 * dotnet by  Chris Larsen of Euphoria Audio  
 Bindings
 --------
 * dotnet by  Chris Larsen of Euphoria Audio  
index c84465d8f6ba736b1b65e2b275fc0f989255e19e..1e4aa4db1848bf58efe18abc2d73d443f803f318 100644 (file)
@@ -4,7 +4,7 @@ rrdgraph_libdbi - fetching data for graphing in rrdtool graph via libdbi
 
 =head1 SYNOPSIS
 
 
 =head1 SYNOPSIS
 
-E<lt>rrdfileE<gt> = B<sql//E<lt>libdbi driverE<gt>/E<lt>driver-option-nameE<gt>=E<lt>driver-option-valueE<gt>/...[/rrdminstepsize=E<lt>stepsizeE<gt>][/rrdfillmissing=E<lt>fill missing n samplesE<gt>]//E<lt>tableE<gt>/E<lt>unixtimestamp columnE<gt>/E<lt>data value columnE<gt>[/derive]/E<lt>where clause 1E<gt>/.../E<lt>where clause nE<gt>>
+E<lt>rrdfileE<gt> = B<sql//E<lt>libdbi driverE<gt>/E<lt>driver-option-nameE<gt>=E<lt>driver-option-valueE<gt>/...[/rrdminstepsize=E<lt>stepsizeE<gt>][/rrdfillmissing=E<lt>fill missing n secondsE<gt>]//E<lt>tableE<gt>/E<lt>unixtimestamp columnE<gt>/E<lt>data value columnE<gt>[/derive]/E<lt>where clause 1E<gt>/.../E<lt>where clause nE<gt>>
 
 =head1 DESCRIPTION
 
 
 =head1 DESCRIPTION
 
@@ -29,9 +29,9 @@ This pseudo-rrd-filename defines a sql datasource:
 
   defines the minimum number of the step-length used for graphing (default: 300 seconds)
 
 
   defines the minimum number of the step-length used for graphing (default: 300 seconds)
 
-=item B</rrdfillmissing>=B<E<lt>fill missing stepsE<gt>>
+=item B</rrdfillmissing>=B<E<lt>fill missing secondsE<gt>>
 
 
-  defines the number of steps to fill with the last value to avoid NaN boxes due to data-insertation jitter (default: 0 steps)
+  defines the number of seconds to fill with the last value to avoid NaN boxes due to data-insertation jitter (default: 0 seconds)
 
 =item B<E<lt>tableE<gt>>
 
 
 =item B<E<lt>tableE<gt>>
 
index 2c4c722ee46ecbbbd8d95ece84c8deb8c4899d5a..b4f0fc7912f012e469423131cffcdb7340e180e9 100644 (file)
@@ -615,7 +615,7 @@ rrd_fetch_fn_libdbi(
        (*data)[idx*(*ds_cnt)+1]=r_value; /* AVG */
        (*data)[idx*(*ds_cnt)+2]=r_value; /* MAX */
        (*data)[idx*(*ds_cnt)+3]=1;       /* COUNT */
        (*data)[idx*(*ds_cnt)+1]=r_value; /* AVG */
        (*data)[idx*(*ds_cnt)+2]=r_value; /* MAX */
        (*data)[idx*(*ds_cnt)+3]=1;       /* COUNT */
-       (*data)[idx*(*ds_cnt)+4]=r_value; /* SIGMA */
+       (*data)[idx*(*ds_cnt)+4]=r_value*r_value; /* SIGMA */
       } else {
        /* MIN */
        if ((*data)[idx*(*ds_cnt)+0]>r_value) { (*data)[idx*(*ds_cnt)+0]=r_value; }
       } else {
        /* MIN */
        if ((*data)[idx*(*ds_cnt)+0]>r_value) { (*data)[idx*(*ds_cnt)+0]=r_value; }
@@ -652,6 +652,30 @@ rrd_fetch_fn_libdbi(
     }
   }
 
     }
   }
 
+  /* Fill in missing values */
+  fillmissing/=(*step);/* Convert from seconds to steps */
+  if (fillmissing>0) {
+    int copy_left=fillmissing;
+    for(idx=1;idx<rows;idx++) {
+      long count=(*data)[idx*(*ds_cnt)+3];
+      if (count==0) {
+        /* No data this bin */
+        if (copy_left>0) {
+          /* But we can copy from previous */
+          int idx_p=idx-1;
+          (*data)[idx*(*ds_cnt)+0]=(*data)[idx_p*(*ds_cnt)+0];
+          (*data)[idx*(*ds_cnt)+1]=(*data)[idx_p*(*ds_cnt)+1];
+          (*data)[idx*(*ds_cnt)+2]=(*data)[idx_p*(*ds_cnt)+2];
+          (*data)[idx*(*ds_cnt)+3]=(*data)[idx_p*(*ds_cnt)+3];
+          (*data)[idx*(*ds_cnt)+4]=(*data)[idx_p*(*ds_cnt)+4];
+          copy_left--;
+        }
+      }else{
+        copy_left=fillmissing;
+      }
+    }
+  }
+
   /* and return OK */
   return 0;
 }
   /* and return OK */
   return 0;
 }