[rrd-developers] [PATCH] set smoothing window

Evan Miller emiller at imvu.com
Mon Sep 10 21:30:10 CEST 2007


OK. I've updated the patch to support the key=value syntax (the code
that achieves this isn't the most extensible, but it works).

In addition, this patch updates rrd_dump.c, rrd_info.c, and
rrd_restore.c, and isn't dumb when dealing with older RRD formats.

Let me know what you think.

Evan

On Sat, Sep 08, 2007 at 07:18:58AM +0200, Tobias Oetiker wrote:
> Hi Evan,
> 
> from an interface standpoint of view, I would prefer that optional
> arguments were using key=value syntax, this will make it possible
> to have other optional arguments added without using the
> 
> bla::optional2
> 
> syntax when not setting
> 
> bla:optional1:optional2
> 
> at the same time
> 
> yes I know that interface is not consistant ... especially in the
> graph area we have 'both' but alas, that is what we get from being
> backward compatible ...
> 
> cheers
> tobi
> 
> 
> Yesterday Evan Miller wrote:
> 
> > Here's a patch to allow the smoothing window size in the archive
> > definition. Old format:
> >
> > RRA:SEASONAL:seasonal period:gamma:rra-num
> > RRA:DEVSEASONAL:seasonal period:gamma:rra-num
> >
> > New (backward-compatible) format:
> >
> > RRA:SEASONAL:seasonal period:gamma:rra-num[:smoothing window]
> > RRA:DEVSEASONAL:seasonal period:gamma:rra-num[:smoothing window]
> >
> > By default it's set to 0.05 (same as now), which means 5% of a season is
> > used for the running average. Setting "smoothing window" to 0 will
> > disable the running-average smoother altogether.
> >
> > Let me know if I've forgotten anything...
> >
> > Evan
> >
> 
> -- 
> Tobi Oetiker, OETIKER+PARTNER AG, Aarweg 15 CH-4600 Olten
> http://it.oetiker.ch tobi at oetiker.ch ++41 62 213 9902
-------------- next part --------------
Index: src/rrd_info.c
===================================================================
--- src/rrd_info.c	(revision 1199)
+++ src/rrd_info.c	(working copy)
@@ -205,6 +205,11 @@
             info.u_val = rrd.rra_def[i].par[RRA_seasonal_gamma].u_val;
             cd = info_push(cd, sprintf_alloc("rra[%d].gamma", i), RD_I_VAL,
                            info);
+            if (atoi(rrd.stat_head->version) >= 4) {
+                    info.u_val = rrd.rra_def[i].par[RRA_seasonal_smoothing_window].u_val;
+                    cd = info_push(cd, sprintf_alloc("rra[%d].smoothing_window", i), RD_I_VAL,
+                                   info);
+            }
             break;
         case CF_FAILURES:
             info.u_val = rrd.rra_def[i].par[RRA_delta_pos].u_val;
Index: src/rrd_dump.c
===================================================================
--- src/rrd_dump.c	(revision 1199)
+++ src/rrd_dump.c	(working copy)
@@ -197,6 +197,11 @@
             fprintf(out_file,
                     "\t\t<seasonal_smooth_idx> %lu </seasonal_smooth_idx>\n",
                     rrd.rra_def[i].par[RRA_seasonal_smooth_idx].u_cnt);
+            if (atoi(rrd.stat_head->version) >= 4) {
+                fprintf(out_file,
+                        "\t\t<smoothing_window> %0.10e </smoothing_window>\n",
+                        rrd.rra_def[i].par[RRA_seasonal_smoothing_window].u_val);
+            }
             fprintf(out_file,
                     "\t\t<dependent_rra_idx> %lu </dependent_rra_idx>\n",
                     rrd.rra_def[i].par[RRA_dependent_rra_idx].u_cnt);
Index: src/rrd_hw.c
===================================================================
--- src/rrd_hw.c	(revision 1199)
+++ src/rrd_hw.c	(working copy)
@@ -139,7 +139,14 @@
     rrd_value_t *working_average;
     rrd_value_t *baseline;
 
-    offset = floor(0.025 * row_count);
+    if (atoi(rrd->stat_head->version) >= 4) {
+        offset = floor(rrd->rra_def[rra_idx].
+                        par[RRA_seasonal_smoothing_window].
+                        u_val / 2 * row_count);
+    } else {
+        offset = floor(0.05 / 2 * row_count);
+    }
+
     if (offset == 0)
         return 0;       /* no smoothing */
 
Index: src/rrd_format.h
===================================================================
--- src/rrd_format.h	(revision 1199)
+++ src/rrd_format.h	(working copy)
@@ -194,13 +194,15 @@
 enum rra_par_en { RRA_cdp_xff_val = 0,  /* what part of the consolidated
                                          * datapoint must be known, to produce a
                                          * valid entry in the rra */
-    RRA_hw_alpha,
+    /* CF_HWPREDICT: */
+    RRA_hw_alpha = 1,
     /* exponential smoothing parameter for the intercept in
      * the Holt-Winters prediction algorithm. */
-    RRA_hw_beta,
+    RRA_hw_beta = 2,
     /* exponential smoothing parameter for the slope in
      * the Holt-Winters prediction algorithm. */
-    RRA_dependent_rra_idx,
+
+    RRA_dependent_rra_idx = 3,
     /* For CF_HWPREDICT: index of the RRA with the seasonal 
      * effects of the Holt-Winters algorithm (of type
      * CF_SEASONAL).
@@ -212,22 +214,30 @@
      * Holt-Winters prediction (of type CF_HWPREDICT).
      * For CF_FAILURES: index of the CF_DEVSEASONAL array.
      * */
-    RRA_seasonal_smooth_idx,
-    /* For CF_SEASONAL and CF_DEVSEASONAL:
-     * an integer between 0 and row_count - 1 which
+
+    /* CF_SEASONAL and CF_DEVSEASONAL: */
+    RRA_seasonal_gamma = 1,
+    /* exponential smoothing parameter for seasonal effects. */
+
+    RRA_seasonal_smoothing_window = 2,
+    /* fraction of the season to include in the running average
+     * smoother */
+
+    /* RRA_dependent_rra_idx = 3, */
+
+    RRA_seasonal_smooth_idx = 4,
+    /* an integer between 0 and row_count - 1 which
      * is index in the seasonal cycle for applying
      * the period smoother. */
-    RRA_failure_threshold,
+
+    /* CF_FAILURES: */
+    RRA_delta_pos = 1, /* confidence bound scaling parameters */
+    RRA_delta_neg = 2,
+    /* RRA_dependent_rra_idx = 3, */
+    RRA_window_len = 4,
+    RRA_failure_threshold = 5,
     /* For CF_FAILURES, number of violations within the last
      * window required to mark a failure. */
-    RRA_seasonal_gamma = RRA_hw_alpha,
-    /* exponential smoothing parameter for seasonal effects.
-     * */
-    RRA_delta_pos = RRA_hw_alpha,
-    RRA_delta_neg = RRA_hw_beta,
-    /* confidence bound scaling parameters for the
-     * the FAILURES RRA. */
-    RRA_window_len = RRA_seasonal_smooth_idx
 };
 
                     /* For CF_FAILURES, the length of the window for measuring
Index: src/rrd_create.c
===================================================================
--- src/rrd_create.c	(revision 1199)
+++ src/rrd_create.c	(working copy)
@@ -264,6 +264,8 @@
                         /* initialize some parameters */
                         rrd.rra_def[rrd.stat_head->rra_cnt].
                             par[RRA_seasonal_gamma].u_val = 0.1;
+                        rrd.rra_def[rrd.stat_head->rra_cnt].
+                            par[RRA_seasonal_smoothing_window].u_val = 0.05;
                         /* fall through */
                     case CF_DEVPREDICT:
                         rrd.rra_def[rrd.stat_head->rra_cnt].
@@ -420,6 +422,25 @@
                             par[RRA_dependent_rra_idx].u_cnt =
                             atoi(token) - 1;
                         break;
+                    case CF_DEVSEASONAL:
+                    case CF_SEASONAL:
+                        /* optional smoothing window */
+                        if (sscanf(token, "smoothing-window=%lf", 
+                                &(rrd.rra_def[rrd.stat_head->rra_cnt].
+                                par[RRA_seasonal_smoothing_window].u_val))) {
+                            strcpy(rrd.stat_head->version, RRD_VERSION); /* smoothing-window causes Version 4 */
+                            if (rrd.rra_def[rrd.stat_head->rra_cnt].
+                                    par[RRA_seasonal_smoothing_window].u_val < 0.0 
+                                    || rrd.rra_def[rrd.stat_head->rra_cnt].
+                                            par[RRA_seasonal_smoothing_window].u_val > 1.0) {
+                                rrd_set_error("Invalid smoothing-window %f: must be between 0 and 1",
+                                    rrd.rra_def[rrd.stat_head->rra_cnt].
+                                            par[RRA_seasonal_smoothing_window].u_val);
+                            }
+                        } else {
+                            rrd_set_error("Invalid option %s", token);
+                        }
+                        break;
                     case CF_HWPREDICT:
                     case CF_MHWPREDICT:
                         /* length of the associated CF_SEASONAL and CF_DEVSEASONAL arrays. */
Index: src/rrd_tune.c
===================================================================
--- src/rrd_tune.c	(revision 1199)
+++ src/rrd_tune.c	(working copy)
@@ -88,6 +88,8 @@
         {"beta", required_argument, 0, 'y'},
         {"gamma", required_argument, 0, 'z'},
         {"gamma-deviation", required_argument, 0, 'v'},
+        {"smoothing-window", required_argument, 0, 's'},
+        {"smoothing-window-deviation", required_argument, 0, 'S'},
         {"aberrant-reset", required_argument, 0, 'b'},
         {0, 0, 0, 0}
     };
@@ -296,6 +298,20 @@
                 return -1;
             }
             break;
+        case 's':
+            strcpy(rrd.stat_head->version, RRD_VERSION);    /* smoothing_window causes Version 4 */
+            if (set_hwarg(&rrd, CF_SEASONAL, RRA_seasonal_smoothing_window, optarg)) {
+                rrd_free(&rrd);
+                return -1;
+            }
+            break;
+        case 'S':
+            strcpy(rrd.stat_head->version, RRD_VERSION);    /* smoothing_window causes Version 4 */
+            if (set_hwarg(&rrd, CF_DEVSEASONAL, RRA_seasonal_smoothing_window, optarg)) {
+                rrd_free(&rrd);
+                return -1;
+            }
+            break;
         case '?':
             if (optopt != 0)
                 rrd_set_error("unknown option '%c'", optopt);
Index: src/rrd_restore.c
===================================================================
--- src/rrd_restore.c	(revision 1199)
+++ src/rrd_restore.c	(working copy)
@@ -383,6 +383,11 @@
                     read_tag(&ptr2, "seasonal_smooth_idx", "%lu",
                              &(rrd->rra_def[rra_index].
                                par[RRA_seasonal_smooth_idx].u_cnt));
+                    if (atoi(rrd->stat_head->version) >= 4) {
+                        read_tag(&ptr2, "smoothing_window", "%lf",
+                                &(rrd->rra_def[rra_index].
+                                  par[RRA_seasonal_smoothing_window].u_val));
+                    }
                     read_tag(&ptr2, "dependent_rra_idx", "%lu",
                              &(rrd->rra_def[rra_index].
                                par[RRA_dependent_rra_idx].u_cnt));
Index: doc/rrdcreate.pod
===================================================================
--- doc/rrdcreate.pod	(revision 1199)
+++ doc/rrdcreate.pod	(working copy)
@@ -238,11 +238,11 @@
 
 =item *
 
-B<RRA:>I<SEASONAL>B<:>I<seasonal period>B<:>I<gamma>B<:>I<rra-num>
+B<RRA:>I<SEASONAL>B<:>I<seasonal period>B<:>I<gamma>B<:>I<rra-num>[B<:smoothing-window=>I<fraction>]
 
 =item *
 
-B<RRA:>I<DEVSEASONAL>B<:>I<seasonal period>B<:>I<gamma>B<:>I<rra-num>
+B<RRA:>I<DEVSEASONAL>B<:>I<seasonal period>B<:>I<gamma>B<:>I<rra-num>[B<:smoothing-window=>I<fraction>]
 
 =item *
 
@@ -342,6 +342,13 @@
 be the same for both. Note that I<gamma> can also be changed via the
 B<RRDtool> I<tune> command.
 
+I<smoothing-window> specifies the fraction of a season that should be
+averaged around each point. By default, the value of I<smoothing-window> is
+0.05, which means each value in SEASONAL and DEVSEASONAL will be occasionally
+replaced by averaging it with its (I<seasonal period>*0.05) nearest neighbors.
+Setting I<smoothing-window> to zero will disable the running-average smoother
+altogether.
+
 I<rra-num> provides the links between related B<RRAs>. If HWPREDICT is
 specified alone and the other B<RRAs> are created implicitly, then
 there is no need to worry about this argument. If B<RRAs> are created
Index: doc/rrdtune.pod
===================================================================
--- doc/rrdtune.pod	(revision 1199)
+++ doc/rrdtune.pod	(working copy)
@@ -18,6 +18,8 @@
 S<[B<--beta> I<adaption-parameter>]>
 S<[B<--gamma> I<adaption-parameter>]>
 S<[B<--gamma-deviation> I<adaption-parameter>]>
+S<[B<--smoothing-window> I<fraction-of-season>]>
+S<[B<--smoothing-window-deviation> I<fraction-of-season>]>
 S<[B<--aberrant-reset> I<ds-name>]>
 
 =head1 DESCRIPTION
@@ -117,6 +119,16 @@
 Alter the seasonal deviation adaptation parameter for the DEVSEASONAL
 B<RRA>. This parameter must be between 0 and 1.
 
+=item S<B<--smoothing-window> I<fraction-of-season>>
+
+Alter the size of the smoothing window for the SEASONAL B<RRA>. This must
+be between 0 and 1.
+
+=item S<B<--smoothing-window-deviation> I<fraction-of-season>>
+
+Alter the size of the smoothing window for the DEVSEASONAL B<RRA>. This must
+be between 0 and 1.
+
 =item S<B<--aberrant-reset> I<ds-name>>
 
 This option causes the aberrant behavior detection algorithm to reset


More information about the rrd-developers mailing list