X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcsv.c;h=5c43b8a87421b312216281aa4562fe47b11d7703;hb=bf90793e82989b1c36fe8f3b66b9c9fe05c9532d;hp=a94b7001025419602961980efa993506e9755b33;hpb=66b7c4bce4e628d8c11cc6762621f155bd68536d;p=collectd.git diff --git a/src/csv.c b/src/csv.c index a94b7001..5c43b8a8 100644 --- a/src/csv.c +++ b/src/csv.c @@ -1,6 +1,7 @@ /** * collectd - src/csv.c - * Copyright (C) 2007 Florian octo Forster + * Copyright (C) 2007-2009 Florian octo Forster + * Copyright (C) 2009 Doug MacEachern * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -17,12 +18,14 @@ * * Authors: * Florian octo Forster + * Doug MacEachern **/ #include "collectd.h" #include "plugin.h" #include "common.h" #include "utils_cache.h" +#include "utils_parse_option.h" /* * Private variables @@ -36,6 +39,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 +150,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 +205,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) { @@ -236,7 +251,8 @@ static int csv_config (const char *key, const char *value) return (0); } /* int csv_config */ -static int csv_write (const data_set_t *ds, const value_list_t *vl) +static int csv_write (const data_set_t *ds, const value_list_t *vl, + user_data_t __attribute__((unused)) *user_data) { struct stat statbuf; char filename[512]; @@ -259,6 +275,27 @@ 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) + { + size_t i; + + escape_string (filename, sizeof (filename)); + + /* Replace commas by colons for PUTVAL compatible output. */ + for (i = 0; i < sizeof (values); i++) + { + if (values[i] == 0) + break; + else if (values[i] == ',') + values[i] = ':'; + } + + fprintf (use_stdio == 1 ? stdout : stderr, + "PUTVAL %s interval=%i %s\n", + filename, interval_g, values); + return (0); + } + if (stat (filename, &statbuf) == -1) { if (errno == ENOENT) @@ -322,5 +359,5 @@ void module_register (void) { plugin_register_config ("csv", csv_config, config_keys, config_keys_num); - plugin_register_write ("csv", csv_write); + plugin_register_write ("csv", csv_write, /* user_data = */ NULL); } /* void module_register */