From: Florian Forster Date: Fri, 12 Oct 2012 06:16:17 +0000 (+0200) Subject: src/utils_format_graphite.[ch]: Add the "store_rates" option. X-Git-Tag: collectd-5.2.0~35 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9e895cf1cfa418fe8bd4e3f63045ff3cd9f28b70;p=collectd.git src/utils_format_graphite.[ch]: Add the "store_rates" option. This functionality must have been lost in the refactoring that added Graphite support to the AMQP plugin. --- diff --git a/src/amqp.c b/src/amqp.c index 876f7e9e..c9e46c45 100644 --- a/src/amqp.c +++ b/src/amqp.c @@ -791,7 +791,8 @@ static int camqp_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */ else if (conf->format == CAMQP_FORMAT_GRAPHITE) { status = format_graphite (buffer, sizeof (buffer), ds, vl, - conf->prefix, conf->postfix, conf->escape_char); + conf->prefix, conf->postfix, conf->escape_char, + conf->store_rates); if (status != 0) { ERROR ("amqp plugin: format_graphite failed with status %i.", diff --git a/src/utils_format_graphite.c b/src/utils_format_graphite.c index 49a59c50..b9b906fa 100644 --- a/src/utils_format_graphite.c +++ b/src/utils_format_graphite.c @@ -33,7 +33,8 @@ * Largely taken from write_graphite.c as it remains the same formatting */ static int gr_format_values (char *ret, size_t ret_len, - int ds_num, const data_set_t *ds, const value_list_t *vl) + int ds_num, const data_set_t *ds, const value_list_t *vl, + gauge_t const *rates) { size_t offset = 0; int status; @@ -59,6 +60,8 @@ static int gr_format_values (char *ret, size_t ret_len, if (ds->ds[ds_num].type == DS_TYPE_GAUGE) BUFFER_ADD ("%f", vl->values[ds_num].gauge); + else if (rates != NULL) + BUFFER_ADD ("%f", rates[ds_num]); else if (ds->ds[ds_num].type == DS_TYPE_COUNTER) BUFFER_ADD ("%llu", vl->values[ds_num].counter); else if (ds->ds[ds_num].type == DS_TYPE_DERIVE) @@ -165,12 +168,17 @@ static int gr_format_name (char *ret, int ret_len, int format_graphite (char *buffer, size_t buffer_size, const data_set_t *ds, const value_list_t *vl, char *prefix, - char *postfix, char escape_char) + char *postfix, char escape_char, + _Bool store_rates) { int status = 0; int i; int buffer_pos = 0; + gauge_t *rates = NULL; + if (store_rates) + rates = uc_get_rate (ds, vl); + for (i = 0; i < ds->ds_num; i++) { const char *ds_name = NULL; @@ -186,17 +194,19 @@ int format_graphite (char *buffer, size_t buffer_size, prefix, postfix, escape_char); if (status != 0) { - ERROR ("amqp plugin: error with gr_format_name"); + ERROR ("format_graphite: error with gr_format_name"); + sfree (rates); return (status); } escape_string (key, sizeof (key)); /* Convert the values to an ASCII representation and put that into * `values'. */ - status = gr_format_values (values, sizeof (values), i, ds, vl); + status = gr_format_values (values, sizeof (values), i, ds, vl, rates); if (status != 0) { ERROR ("format_graphite: error with gr_format_values"); + sfree (rates); return (status); } @@ -209,6 +219,7 @@ int format_graphite (char *buffer, size_t buffer_size, if (message_len >= sizeof (message)) { ERROR ("format_graphite: message buffer too small: " "Need %zu bytes.", message_len + 1); + sfree (rates); return (-ENOMEM); } @@ -216,11 +227,13 @@ int format_graphite (char *buffer, size_t buffer_size, if ((buffer_pos + message_len) >= buffer_size) { ERROR ("format_graphite: target buffer too small"); + sfree (rates); return (-ENOMEM); } memcpy((void *) (buffer + buffer_pos), message, message_len); buffer_pos += message_len; } + sfree (rates); return (status); } /* int format_graphite */ diff --git a/src/utils_format_graphite.h b/src/utils_format_graphite.h index a3c4d85c..a7a05bbb 100644 --- a/src/utils_format_graphite.h +++ b/src/utils_format_graphite.h @@ -28,6 +28,7 @@ int format_graphite (char *buffer, size_t buffer_size, const data_set_t *ds, const value_list_t *vl, const char *prefix, - const char *postfix, const char escape_char); + const char *postfix, const char escape_char, + _Bool store_rates); #endif /* UTILS_FORMAT_GRAPHITE_H */ diff --git a/src/write_graphite.c b/src/write_graphite.c index f3753da2..2ae30efe 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -352,7 +352,7 @@ static int wg_write_messages (const data_set_t *ds, const value_list_t *vl, memset (buffer, 0, sizeof (buffer)); status = format_graphite (buffer, sizeof (buffer), ds, vl, - cb->prefix, cb->postfix, cb->escape_char); + cb->prefix, cb->postfix, cb->escape_char, cb->store_rates); if (status != 0) /* error message has been printed already. */ return (status);