Code

write_http plugin: Add a StoreRates option.
authorPaul Sadauskas <psadauskas@gmail.com>
Mon, 15 Feb 2010 04:18:58 +0000 (21:18 -0700)
committerSebastian Harl <sh@tokkee.org>
Thu, 25 Feb 2010 23:21:37 +0000 (00:21 +0100)
Signed-off-by: Sebastian Harl <sh@tokkee.org>
src/collectd.conf.pod
src/write_http.c

index 3a6f9a28b55c0001ccd425e54f90013d24401bd7..09508f70add086d1360357363132b6f7eedf9203 100644 (file)
@@ -4237,6 +4237,12 @@ create output in the I<JavaScript Object Notation> (JSON).
 
 Defaults to B<Command>.
 
+=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
 
 =head1 THRESHOLD CONFIGURATION
index 1a490399ec30e18fd863740fb1094b4baa94100c..62e3cf3be067d0cb391ae798f734247cce621cc0 100644 (file)
@@ -49,6 +49,7 @@ struct wh_callback_s
         int   verify_peer;
         int   verify_host;
         char *cacert;
+        int   store_rates;
 
 #define WH_FORMAT_COMMAND 0
 #define WH_FORMAT_JSON    1
@@ -271,11 +272,13 @@ static void wh_callback_free (void *data) /* {{{ */
 
 static int wh_value_list_to_string (char *buffer, /* {{{ */
                 size_t buffer_size,
-                const data_set_t *ds, const value_list_t *vl)
+                const data_set_t *ds, const value_list_t *vl,
+                wh_callback_t *cb)
 {
         size_t offset = 0;
         int status;
         int i;
+       gauge_t *rates = NULL;
 
         assert (0 == strcmp (ds->type, vl->type));
 
@@ -299,7 +302,22 @@ static int wh_value_list_to_string (char *buffer, /* {{{ */
         if (ds->ds[i].type == DS_TYPE_GAUGE)
                 BUFFER_ADD (":%f", vl->values[i].gauge);
         else if (ds->ds[i].type == DS_TYPE_COUNTER)
-                BUFFER_ADD (":%llu", vl->values[i].counter);
+        {
+                if (cb->store_rates != 0) 
+                {
+                       if (rates == NULL)
+                               rates = uc_get_rate (ds, vl);
+                       if (rates == NULL)
+                       {
+                               WARNING ("write_http plugin: "
+                                               "uc_get_rate failed.");
+                               return (-1);
+                       }
+                        BUFFER_ADD (":%lf", rates[i]);
+                }
+                else
+                        BUFFER_ADD (":%llu", vl->values[i].counter);
+        }
         else if (ds->ds[i].type == DS_TYPE_DERIVE)
                 BUFFER_ADD (":%"PRIi64, vl->values[i].derive);
         else if (ds->ds[i].type == DS_TYPE_ABSOLUTE)
@@ -343,7 +361,7 @@ static int wh_write_command (const data_set_t *ds, const value_list_t *vl, /* {{
 
         /* Convert the values to an ASCII representation and put that into
          * `values'. */
-        status = wh_value_list_to_string (values, sizeof (values), ds, vl);
+        status = wh_value_list_to_string (values, sizeof (values), ds, vl, cb);
         if (status != 0) {
                 ERROR ("write_http plugin: error with "
                                 "wh_value_list_to_string");
@@ -589,6 +607,8 @@ static int wh_config_url (oconfig_item_t *ci) /* {{{ */
                         config_set_string (&cb->cacert, child);
                 else if (strcasecmp ("Format", child->key) == 0)
                         config_set_format (cb, child);
+                else if (strcasecmp ("StoreRates", child->key) == 0)
+                        config_set_boolean (&cb->store_rates, child);
                 else
                 {
                         ERROR ("write_http plugin: Invalid configuration "