From a92df91091855f18cbf9191a7e604a5dcd23852b Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 12 Feb 2007 19:55:19 +0100 Subject: [PATCH] rrdtool plugin: Implemented a `DataDir' config option to be able to store the RRD-files anywhere. --- src/collectd.conf.pod | 5 +++++ src/rrdtool.c | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 45acb682..33690ee5 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -318,6 +318,11 @@ at once reduces IO-operations and thus lessens the load produced by updating the files. The tradeoff is that the graphs kind of "drag behind" and that more memory is used. +=item B I + +Set the directory to store RRD-files under. Per default RRD-files are generated +beneath the daemons working directory, i.Ee. the B. + =back =head2 Plugin C diff --git a/src/rrdtool.c b/src/rrdtool.c index 5a9fa8c6..beb5a73e 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -76,9 +76,12 @@ static int rra_types_num = 3; static const char *config_keys[] = { "CacheTimeout", + "DataDir", NULL }; -static int config_keys_num = 1; +static int config_keys_num = 2; + +static char *datadir = NULL; static int cache_timeout = 0; static time_t cache_flush; @@ -365,6 +368,15 @@ static int value_list_to_filename (char *buffer, int buffer_len, int offset = 0; int status; + if (datadir != NULL) + { + status = snprintf (buffer + offset, buffer_len - offset, + "%s/", datadir); + if ((status < 1) || (status >= buffer_len - offset)) + return (-1); + offset += status; + } + status = snprintf (buffer + offset, buffer_len - offset, "%s/", vl->host); if ((status < 1) || (status >= buffer_len - offset)) @@ -617,6 +629,26 @@ static int rrd_config (const char *key, const char *val) } cache_timeout = tmp; } + else if (strcasecmp ("DataDir", key) == 0) + { + if (datadir != NULL) + free (datadir); + datadir = strdup (val); + if (datadir != NULL) + { + int len = strlen (datadir); + while ((len > 0) && (datadir[len - 1] == '/')) + { + len--; + datadir[len] = '\0'; + } + if (len <= 0) + { + free (datadir); + datadir = NULL; + } + } + } else { return (-1); -- 2.11.0