Hello, I've been experimenting with using the holt-winters prediction in rrdtool and figured it would be really nice to have the option for collectd to create RRDs with the HWPREDICT RRAs. The attached patch adds three configuration options, HWPredictSeasonTimespan (the seasonality of your data in seconds -- set this to something non-zero to enable), HWPredictAlpha (determines the rate of intercept adaptation for holt-winters, defaults to 0.01. Higher adapts faster.) and HWPredictBeta (determines the rate of slope adaptation, defaults to 0.00035, higher adapts faster).
Seems to work properly in my testing, resulting in RRDs with all the necessary RRAs. I'm using the simple method of creating these, passing only the HWPREDICT definition and allowing RRDtool to automatically create the appropriate sized record-keeping RRAs. One word of caution: depending on the step-size chosen for your RRDs, this can result in much larger RRDs. Holt-Winters works on the raw data points, not aggregated data points, which can produce some big RRAs. If your step size is 10 seconds and your data is periodic over a week, this will result in RRAs with 60480 rows. Practically, it means that the RRD filesize goes from 58KB to 2.4MB. I suppose that's the price to be paid if you need to prediction functionality, though. Anyway, hopefully someone else finds this useful! --Shaun
From c540b2e538658f04ae42909a847eae910df44a45 Mon Sep 17 00:00:00 2001 From: Shaun Lindsay <[email protected]> Date: Wed, 15 Sep 2010 15:40:00 -0700 Subject: [PATCH] allow configuration and addition of holt-winters prediction RRAs fixing the formatting style to match the rest of collectd allow configuration and addition of holt-winters prediction RRAs --- src/rrdtool.c | 27 +++++++++++++++++++++++++-- src/utils_rrdcreate.c | 18 ++++++++++++++++++ src/utils_rrdcreate.h | 3 +++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/rrdtool.c b/src/rrdtool.c index 4655b96..ad51458 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -82,7 +82,10 @@ static const char *config_keys[] = "RRATimespan", "XFF", "WritesPerSecond", - "RandomTimeout" + "RandomTimeout", + "HWPredictSeasonTimespan", + "HWPredictAlpha", + "HWPredictBeta" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -102,7 +105,10 @@ static rrdcreate_config_t rrdcreate_config = /* timespans_num = */ 0, /* consolidation_functions = */ NULL, - /* consolidation_functions_num = */ 0 + /* consolidation_functions_num = */ 0, + /* hwpredict_season_timespan = */ 0, + /* hwpredict_alpha = */ 0.01, + /* hwpredict_beta = */ 0.00035 }; /* XXX: If you need to lock both, cache_lock and queue_lock, at the same time, @@ -1075,6 +1081,23 @@ static int rrd_config (const char *key, const char *value) { random_timeout = tmp; } + } else if (strcasecmp ("HWPredictSeasonTimespan", key) == 0) + { + int tmp; + tmp = atoi(value); + rrdcreate_config.hwpredict_season_timespan = tmp; + } + else if (strcasecmp ("HWPredictAlpha", key) == 0) + { + float tmp; + tmp = atof(value); + rrdcreate_config.hwpredict_alpha = tmp; + } + else if (strcasecmp ("HWPredictBeta", key) == 0) + { + float tmp; + tmp = atof(value); + rrdcreate_config.hwpredict_beta = tmp; } else { diff --git a/src/utils_rrdcreate.c b/src/utils_rrdcreate.c index 4ecec59..1065bfb 100644 --- a/src/utils_rrdcreate.c +++ b/src/utils_rrdcreate.c @@ -123,6 +123,10 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */ } rra_max = rts_num * rra_types_num; + if (cfg->hwpredict_season_timespan > 0) + { + rra_max += 1; + } if ((rra_def = (char **) malloc ((rra_max + 1) * sizeof (char *))) == NULL) return (-1); @@ -166,6 +170,20 @@ static int rra_get (char ***ret, const value_list_t *vl, /* {{{ */ } } + if (cfg->hwpredict_season_timespan > 0) + { + int season_len = (int) ceil (((double) cfg->hwpredict_season_timespan) / + ((double) ss)); + + int status = ssnprintf(buffer, sizeof(buffer), "RRA:HWPREDICT:%d:%f:%f:%d", + season_len, cfg->hwpredict_alpha, cfg->hwpredict_beta, season_len); + + if ((status < 0) || ((size_t) status >= sizeof (buffer))) + ERROR ("rra_get: Buffer would have been truncated."); + else + rra_def[rra_num++] = sstrdup (buffer); + } + *ret = rra_def; return (rra_num); } /* }}} int rra_get */ diff --git a/src/utils_rrdcreate.h b/src/utils_rrdcreate.h index 935e4e0..0c76e9b 100644 --- a/src/utils_rrdcreate.h +++ b/src/utils_rrdcreate.h @@ -38,6 +38,9 @@ struct rrdcreate_config_s char **consolidation_functions; size_t consolidation_functions_num; + int hwpredict_season_timespan; + float hwpredict_alpha; + float hwpredict_beta; }; typedef struct rrdcreate_config_s rrdcreate_config_t; -- 1.5.5.6
_______________________________________________ collectd mailing list [email protected] http://mailman.verplant.org/listinfo/collectd
