From f950fcd91292616b3c4d98cbc4f44e0b4f781d8b Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 2 Jan 2009 13:26:01 -0800 Subject: [PATCH] csv plugin: Make it possible to write values to STDOUT. Signed-off-by: Doug MacEachern Signed-off-by: Florian Forster --- src/collectd.conf.pod | 3 +++ src/csv.c | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 5a253689..1b07fa83 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -273,6 +273,9 @@ installed and an "cpu governor" (that's a kernel module) is loaded. Set the directory to store CSV-files under. Per default CSV-files are generated beneath the daemon's working directory, i.Ee. the B. +The special strings B and B can be used to write to the standard +output and standard error channels, respectively. This, of course, only makes +much sense when collectd is running in foreground- or non-daemon-mode. =item B B diff --git a/src/csv.c b/src/csv.c index a94b7001..b5333b43 100644 --- a/src/csv.c +++ b/src/csv.c @@ -36,6 +36,7 @@ static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); static char *datadir = NULL; static int store_rates = 0; +static int use_stdio = 0; static int value_list_to_string (char *buffer, int buffer_len, const data_set_t *ds, const value_list_t *vl) @@ -146,6 +147,7 @@ static int value_list_to_filename (char *buffer, int buffer_len, return (-1); offset += status; + if (!use_stdio) { time_t now; struct tm stm; @@ -200,6 +202,16 @@ static int csv_config (const char *key, const char *value) { if (datadir != NULL) free (datadir); + if (strcasecmp ("stdout", value) == 0) + { + use_stdio = 1; + return (0); + } + else if (strcasecmp ("stderr", value) == 0) + { + use_stdio = 2; + return (0); + } datadir = strdup (value); if (datadir != NULL) { @@ -259,6 +271,13 @@ static int csv_write (const data_set_t *ds, const value_list_t *vl) if (value_list_to_string (values, sizeof (values), ds, vl) != 0) return (-1); + if (use_stdio) + { + fprintf (use_stdio == 1 ? stdout : stderr, + "%s=%s\n", filename, values); + return (0); + } + if (stat (filename, &statbuf) == -1) { if (errno == ENOENT) -- 2.30.2