Hi List,

I've added a "StoreRates" option to the write_http plugin, similar to
how it works in the csv plugin. I've attached the patch, or there's
this branch on github, which should merge cleanly with 4.9.

Branch: http://github.com/absperf/collectd/commits/collectd-4.9

Thanks,
Paul
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 74c54c5..2e3ca48 100644
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
@@ -4100,6 +4100,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
diff --git a/src/write_http.c b/src/write_http.c
index f14636b..62e3cf3 100644
--- a/src/write_http.c
+++ b/src/write_http.c
@@ -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
@@ -142,7 +143,7 @@ static int wh_callback_init (wh_callback_t *cb) /* {{{ */
                 ssnprintf (cb->credentials, credentials_size, "%s:%s",
                                 cb->user, (cb->pass == NULL) ? "" : cb->pass);
                 curl_easy_setopt (cb->curl, CURLOPT_USERPWD, cb->credentials);
-                curl_easy_setopt (cb->curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
+                curl_easy_setopt (cb->curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
         }
 
         curl_easy_setopt (cb->curl, CURLOPT_SSL_VERIFYPEER, cb->verify_peer);
@@ -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 "
_______________________________________________
collectd mailing list
[email protected]
http://mailman.verplant.org/listinfo/collectd

Reply via email to