From: Florian Forster Date: Thu, 1 Mar 2007 11:14:39 +0000 (+0100) Subject: csv plugin: Add a `DataDir' option. X-Git-Tag: collectd-4.0.0~168 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=3732656b2a43e31a7c5550cca1f94326bf2c4391;p=collectd.git csv plugin: Add a `DataDir' option. Since the `rrdtool' and `csv' plugins may be loaded at the same time, one may want to configure another path for this plugin, too. --- diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 3c34905f..5a04fce7 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -130,6 +130,17 @@ TCP-Port to connect to. Defaults to B<3551>. =back +=head2 Plugin C + +=over 4 + +=item B I + +Set the directory to store RRD-files under. Per default RRD-files are generated +beneath the daemon's working directory, i.Ee. the B. + +=back + =head2 Plugin C =over 4 @@ -346,7 +357,7 @@ can savely ignore these settings. =item B I -Set the directory to store RRD-files under. Per default RRD-files are generated +Set the directory to store CSV-files under. Per default CSV-files are generated beneath the daemon's working directory, i.Ee. the B. =item B I diff --git a/src/csv.c b/src/csv.c index dd33ca5e..268bdbf5 100644 --- a/src/csv.c +++ b/src/csv.c @@ -24,6 +24,17 @@ #include "common.h" #include "utils_debug.h" +/* + * Private variables + */ +static const char *config_keys[] = +{ + "DataDir" +}; +static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); + +static char *datadir = NULL; + static int value_list_to_string (char *buffer, int buffer_len, const data_set_t *ds, const value_list_t *vl) { @@ -66,6 +77,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)) @@ -137,6 +157,35 @@ static int csv_create_file (const char *filename, const data_set_t *ds) return 0; } /* int csv_create_file */ +static int csv_config (const char *key, const char *value) +{ + if (strcasecmp ("DataDir", key) == 0) + { + if (datadir != NULL) + free (datadir); + datadir = strdup (value); + 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); + } + return (0); +} /* int csv_config */ + static int csv_write (const data_set_t *ds, const value_list_t *vl) { struct stat statbuf; @@ -150,6 +199,8 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl) if (value_list_to_filename (filename, sizeof (filename), ds, vl) != 0) return (-1); + DBG ("filename = %s;", filename); + if (value_list_to_string (values, sizeof (values), ds, vl) != 0) return (-1); @@ -210,5 +261,7 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl) void module_register (void) { + plugin_register_config ("csv", csv_config, + config_keys, config_keys_num); plugin_register_write ("csv", csv_write); }