projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
write_riemann plugin: Receive acknowledge message when using TCP.
[collectd.git]
/
src
/
utils_format_graphite.c
diff --git
a/src/utils_format_graphite.c
b/src/utils_format_graphite.c
index
b0ebc1e
..
8351201
100644
(file)
--- a/
src/utils_format_graphite.c
+++ b/
src/utils_format_graphite.c
@@
-1,6
+1,7
@@
/**
* collectd - src/utils_format_graphite.c
* Copyright (C) 2012 Thomas Meson
/**
* 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
*
* 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
@@
-15,23
+16,25
@@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
- * Author:
+ * Author
s
:
* Thomas Meson <zllak at hycik.org>
* Thomas Meson <zllak at hycik.org>
+ * Florian octo Forster <octo at collectd.org>
**/
#include "collectd.h"
#include "plugin.h"
#include "common.h"
**/
#include "collectd.h"
#include "plugin.h"
#include "common.h"
+#include "utils_format_graphite.h"
#include "utils_cache.h"
#include "utils_cache.h"
-#include "utils_format_json.h"
#include "utils_parse_option.h"
/* Utils functions to format data sets in graphite format.
* Largely taken from write_graphite.c as it remains the same formatting */
static int gr_format_values (char *ret, size_t ret_len,
#include "utils_parse_option.h"
/* Utils functions to format data sets in graphite format.
* 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;
{
size_t offset = 0;
int status;
@@
-57,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);
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)
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)
@@
-75,7
+80,7
@@
static int gr_format_values (char *ret, size_t ret_len,
return (0);
}
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;
char escape_char)
{
size_t i;
@@
-103,11
+108,12
@@
static void copy_escape_part (char *dst, const char *src, size_t dst_len,
}
static int gr_format_name (char *ret, int ret_len,
}
static int gr_format_name (char *ret, int ret_len,
- const value_list_t *vl,
- const char *ds_name,
- char *prefix,
- char *postfix,
- char escape_char)
+ value_list_t const *vl,
+ char const *ds_name,
+ char const *prefix,
+ char const *postfix,
+ char const escape_char,
+ unsigned int flags)
{
char n_host[DATA_MAX_NAME_LEN];
char n_plugin[DATA_MAX_NAME_LEN];
{
char n_host[DATA_MAX_NAME_LEN];
char n_plugin[DATA_MAX_NAME_LEN];
@@
-124,21
+130,21
@@
static int gr_format_name (char *ret, int ret_len,
if (postfix == NULL)
postfix = "";
if (postfix == NULL)
postfix = "";
- copy_escape_part (n_host, vl->host,
+
gr_
copy_escape_part (n_host, vl->host,
sizeof (n_host), escape_char);
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);
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);
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);
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')
ssnprintf (tmp_plugin, sizeof (tmp_plugin), "%s%c%s",
n_plugin,
sizeof (n_type_instance), escape_char);
if (n_plugin_instance[0] != '\0')
ssnprintf (tmp_plugin, sizeof (tmp_plugin), "%s%c%s",
n_plugin,
- '-',
+
(flags & GRAPHITE_SEPARATE_INSTANCES) ? '.' :
'-',
n_plugin_instance);
else
sstrncpy (tmp_plugin, n_plugin, sizeof (tmp_plugin));
n_plugin_instance);
else
sstrncpy (tmp_plugin, n_plugin, sizeof (tmp_plugin));
@@
-146,11
+152,13
@@
static int gr_format_name (char *ret, int ret_len,
if (n_type_instance[0] != '\0')
ssnprintf (tmp_type, sizeof (tmp_type), "%s%c%s",
n_type,
if (n_type_instance[0] != '\0')
ssnprintf (tmp_type, sizeof (tmp_type), "%s%c%s",
n_type,
- '-',
+
(flags & GRAPHITE_SEPARATE_INSTANCES) ? '.' :
'-',
n_type_instance);
else
sstrncpy (tmp_type, n_type, sizeof (tmp_type));
n_type_instance);
else
sstrncpy (tmp_type, n_type, sizeof (tmp_type));
+ /* Assert always_append_ds -> ds_name */
+ assert (!(flags & GRAPHITE_ALWAYS_APPEND_DS) || (ds_name != NULL));
if (ds_name != NULL)
ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s",
prefix, n_host, postfix, tmp_plugin, tmp_type, ds_name);
if (ds_name != NULL)
ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s",
prefix, n_host, postfix, tmp_plugin, tmp_type, ds_name);
@@
-162,39
+170,48
@@
static int gr_format_name (char *ret, int ret_len,
}
int format_graphite (char *buffer, size_t buffer_size,
}
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)
+ data_set_t const *ds, value_list_t const *vl,
+ char const *prefix, char const *postfix, char const escape_char,
+ unsigned int flags)
{
int status = 0;
int i;
int buffer_pos = 0;
{
int status = 0;
int i;
int buffer_pos = 0;
+ gauge_t *rates = NULL;
+ if (flags & GRAPHITE_STORE_RATES)
+ rates = uc_get_rate (ds, vl);
+
for (i = 0; i < ds->ds_num; i++)
{
for (i = 0; i < ds->ds_num; i++)
{
- c
onst char
*ds_name = NULL;
+ c
har const
*ds_name = NULL;
char key[10*DATA_MAX_NAME_LEN];
char values[512];
size_t message_len;
char message[1024];
char key[10*DATA_MAX_NAME_LEN];
char values[512];
size_t message_len;
char message[1024];
- ds_name = ds->ds[i].name;
+ if ((flags & GRAPHITE_ALWAYS_APPEND_DS)
+ || (ds->ds_num > 1))
+ ds_name = ds->ds[i].name;
/* Copy the identifier to `key' and escape it. */
status = gr_format_name (key, sizeof (key), vl, ds_name,
/* Copy the identifier to `key' and escape it. */
status = gr_format_name (key, sizeof (key), vl, ds_name,
- prefix, postfix, escape_char);
+ prefix, postfix, escape_char
, flags
);
if (status != 0)
{
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'. */
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");
if (status != 0)
{
ERROR ("format_graphite: error with gr_format_values");
+ sfree (rates);
return (status);
}
return (status);
}
@@
-207,6
+224,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);
if (message_len >= sizeof (message)) {
ERROR ("format_graphite: message buffer too small: "
"Need %zu bytes.", message_len + 1);
+ sfree (rates);
return (-ENOMEM);
}
return (-ENOMEM);
}
@@
-214,11
+232,13
@@
int format_graphite (char *buffer, size_t buffer_size,
if ((buffer_pos + message_len) >= buffer_size)
{
ERROR ("format_graphite: target buffer too small");
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;
}
return (-ENOMEM);
}
memcpy((void *) (buffer + buffer_pos), message, message_len);
buffer_pos += message_len;
}
+ sfree (rates);
return (status);
} /* int format_graphite */
return (status);
} /* int format_graphite */