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.",
* 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;
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)
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;
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);
}
if (message_len >= sizeof (message)) {
ERROR ("format_graphite: message buffer too small: "
"Need %zu bytes.", message_len + 1);
+ sfree (rates);
return (-ENOMEM);
}
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 */
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);