[rrd-developers] Suggestion for NAN-safe TREND operation

Timo Stripf tstripf at gmx.de
Mon Jun 11 00:15:55 CEST 2007


Hello,

i'm using the TREND operation for performance statistic of some self 
written daemons. In my rrd data i have often short periods of missing 
data. In result the trend curve is missing over the complete sliding 
window. So i modified the TREND function to ignore NAN-number. I 
suggest to implement the NAN-safe trend function as OP_TRENDNAN. Here 
is the source:

             case OP_TREND:
             case OP_TRENDNAN:
                 stackunderflow(1);
                 if ((rpi < 2) || (rpnp[rpi-2].op != OP_VARIABLE)) {
                     rrd_set_error("malformed trend arguments");
                     return -1;
                 } else {
                     time_t dur = (time_t)rpnstack -> s[stptr];
                     time_t step = (time_t)rpnp[rpi-2].step;

                     if (output_idx > (int)ceil((float)dur / (float)step)) {
                         int ignorenan = (rpnp[rpi].op == OP_TREND);
                         double accum = 0.0;
                         int i = 0;
                         int count = 0;

                         do {
                             double val = 
rpnp[rpi-2].data[rpnp[rpi-2].ds_cnt * i--];
                             if (ignorenan || !isnan(val)) {
                                 accum += val;
                                 ++count;
                             }

                             dur -= step;
                         } while (dur > 0);

                         rpnstack -> s[--stptr] = (count == 0) ? DNAN 
: (accum / count);
                     } else
                         rpnstack -> s[--stptr] = DNAN;
                 }
                 break;

Best regards
Timo Stripf



More information about the rrd-developers mailing list