Code

csv plugin: Add the possibility to store rates of counter DSes.
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sat, 10 Nov 2007 15:09:03 +0000 (16:09 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sat, 10 Nov 2007 15:09:03 +0000 (16:09 +0100)
src/collectd.conf.in
src/collectd.conf.pod
src/csv.c

index 58de5258cb2b19ba1150531671c23c66b752bf27..60046c05baeecb2c26bf164d422291511e5e2a31 100644 (file)
@@ -74,6 +74,7 @@
 
 #<Plugin csv>
 #      DataDir "@prefix@/var/lib/@PACKAGE_NAME@/csv"
+#      StoreRates false
 #</Plugin>
 
 #<Plugin df>
index b1fcc91a90d9c6852d4cc5d7de41b44a1faf3d52..004a66616ae5988509b8449d5340f50067158cb2 100644 (file)
@@ -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.E<nbsp>e. the B<BaseDir>.
 
+=item B<StoreRates> B<true|false>
+
+If set to B<true>, convert counter values to rates. If set to B<false> (the
+default) counter values are stored as is, i.E<nbsp>e. as an increasing integer
+number.
+
 =back
 
 =head2 Plugin C<df>
index 192cf52e1f4d01518844b6c5997c4e2263a2c9ee..ff59f91c006e81511b6aeec738000398ed945bdc 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
 #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);