From 062c88e486b4b1a09d7dd416c07a2678b4dd7b21 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 10 Nov 2007 16:09:03 +0100 Subject: [PATCH] csv plugin: Add the possibility to store rates of counter DSes. --- src/collectd.conf.in | 1 + src/collectd.conf.pod | 6 +++++ src/csv.c | 52 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 58de5258..60046c05 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -74,6 +74,7 @@ # # DataDir "@prefix@/var/lib/@PACKAGE_NAME@/csv" +# StoreRates false # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index b1fcc91a..004a6661 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -175,6 +175,12 @@ 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. +=item B B + +If set to B, convert counter values to rates. If set to B (the +default) counter values are stored as is, i.Ee. as an increasing integer +number. + =back =head2 Plugin C diff --git a/src/csv.c b/src/csv.c index 192cf52e..ff59f91c 100644 --- a/src/csv.c +++ b/src/csv.c @@ -22,17 +22,20 @@ #include "collectd.h" #include "plugin.h" #include "common.h" +#include "utils_cache.h" /* * Private variables */ static const char *config_keys[] = { - "DataDir" + "DataDir", + "StoreRates" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); static char *datadir = NULL; +static int store_rates = 0; static int value_list_to_string (char *buffer, int buffer_len, const data_set_t *ds, const value_list_t *vl) @@ -40,6 +43,7 @@ static int value_list_to_string (char *buffer, int buffer_len, int offset; int status; int i; + gauge_t *rates = NULL; memset (buffer, '\0', buffer_len); @@ -55,18 +59,45 @@ static int value_list_to_string (char *buffer, int buffer_len, return (-1); if (ds->ds[i].type == DS_TYPE_COUNTER) - status = snprintf (buffer + offset, buffer_len - offset, - ",%llu", vl->values[i].counter); - else + { + if (store_rates == 0) + { + status = snprintf (buffer + offset, + buffer_len - offset, + ",%llu", + vl->values[i].counter); + } + else /* if (store_rates == 1) */ + { + if (rates == NULL) + rates = uc_get_rate (ds, vl); + if (rates == NULL) + { + WARNING ("csv plugin: " + "uc_get_rate failed."); + return (-1); + } + status = snprintf (buffer + offset, + buffer_len - offset, + ",%lf", rates[i]); + } + } + else /* if (ds->ds[i].type == DS_TYPE_GAUGE) */ + { status = snprintf (buffer + offset, buffer_len - offset, ",%lf", vl->values[i].gauge); + } if ((status < 1) || (status >= (buffer_len - offset))) + { + sfree (rates); return (-1); + } offset += status; } /* for ds->ds_num */ + sfree (rates); return (0); } /* int value_list_to_string */ @@ -181,6 +212,19 @@ static int csv_config (const char *key, const char *value) } } } + else if (strcasecmp ("StoreRates", key) == 0) + { + if ((strcasecmp ("True", value) == 0) + || (strcasecmp ("Yes", value) == 0) + || (strcasecmp ("On", value) == 0)) + { + store_rates = 1; + } + else + { + store_rates = 0; + } + } else { return (-1); -- 2.30.2