index b0ebc1ebf05e2f99fc36c8ada8e678b3aed5d16b..b9b906fa373943b427e02d2b72f1fb39d3f21ed6 100644 (file)
/**
* collectd - src/utils_format_graphite.c
* Copyright (C) 2012 Thomas Meson
+ * Copyright (C) 2012 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
- * Author:
+ * Authors:
* Thomas Meson <zllak at hycik.org>
+ * Florian octo Forster <octo at collectd.org>
**/
#include "collectd.h"
* 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)
return (0);
}
-static void copy_escape_part (char *dst, const char *src, size_t dst_len,
+static void gr_copy_escape_part (char *dst, const char *src, size_t dst_len,
char escape_char)
{
size_t i;
if (postfix == NULL)
postfix = "";
- copy_escape_part (n_host, vl->host,
+ gr_copy_escape_part (n_host, vl->host,
sizeof (n_host), escape_char);
- copy_escape_part (n_plugin, vl->plugin,
+ gr_copy_escape_part (n_plugin, vl->plugin,
sizeof (n_plugin), escape_char);
- copy_escape_part (n_plugin_instance, vl->plugin_instance,
+ gr_copy_escape_part (n_plugin_instance, vl->plugin_instance,
sizeof (n_plugin_instance), escape_char);
- copy_escape_part (n_type, vl->type,
+ gr_copy_escape_part (n_type, vl->type,
sizeof (n_type), escape_char);
- copy_escape_part (n_type_instance, vl->type_instance,
+ gr_copy_escape_part (n_type_instance, vl->type_instance,
sizeof (n_type_instance), escape_char);
if (n_plugin_instance[0] != '\0')
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 */