summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7ca030d)
raw | patch | inline | side by side (parent: 7ca030d)
author | Florian Forster <octo@collectd.org> | |
Thu, 13 Dec 2012 08:52:22 +0000 (09:52 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 13 Dec 2012 08:52:22 +0000 (09:52 +0100) |
Fixes Github issue #214.
src/amqp.c | patch | blob | history | |
src/utils_format_graphite.c | patch | blob | history | |
src/utils_format_graphite.h | patch | blob | history | |
src/write_graphite.c | patch | blob | history |
diff --git a/src/amqp.c b/src/amqp.c
index 9c8c6e537c6cb1d2f3907402f7c602e2f8b326b6..767a8776bbfb07ce2a26f932cf7fb5da4d22d047 100644 (file)
--- a/src/amqp.c
+++ b/src/amqp.c
char *prefix;
char *postfix;
char escape_char;
+ unsigned int graphite_flags;
/* subscribe only */
char *exchange_type;
{
status = format_graphite (buffer, sizeof (buffer), ds, vl,
conf->prefix, conf->postfix, conf->escape_char,
- conf->store_rates);
+ conf->graphite_flags);
if (status != 0)
{
ERROR ("amqp plugin: format_graphite failed with status %i.",
conf->delivery_mode = CAMQP_DM_VOLATILE;
}
else if ((strcasecmp ("StoreRates", child->key) == 0) && publish)
+ {
status = cf_util_get_boolean (child, &conf->store_rates);
+ (void) cf_util_get_flag (child, &conf->graphite_flags,
+ GRAPHITE_STORE_RATES);
+ }
else if ((strcasecmp ("Format", child->key) == 0) && publish)
status = camqp_config_set_format (child, conf);
else if ((strcasecmp ("GraphitePrefix", child->key) == 0) && publish)
index b9b906fa373943b427e02d2b72f1fb39d3f21ed6..83512015898e22b27c527b431aa03bdcda5f2865 100644 (file)
#include "plugin.h"
#include "common.h"
+#include "utils_format_graphite.h"
#include "utils_cache.h"
-#include "utils_format_json.h"
#include "utils_parse_option.h"
/* Utils functions to format data sets in graphite format.
}
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];
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));
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));
+ /* 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);
}
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,
- _Bool store_rates)
+ 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;
gauge_t *rates = NULL;
- if (store_rates)
+ if (flags & GRAPHITE_STORE_RATES)
rates = uc_get_rate (ds, vl);
for (i = 0; i < ds->ds_num; i++)
{
- const char *ds_name = NULL;
+ char const *ds_name = NULL;
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,
- prefix, postfix, escape_char);
+ prefix, postfix, escape_char, flags);
if (status != 0)
{
ERROR ("format_graphite: error with gr_format_name");
index a7a05bbbadfea7f006801b6649beb7ed56656f85..398defbeabab0b31c8de7916df1ba2b9e86eca8c 100644 (file)
#include "collectd.h"
#include "plugin.h"
+#define GRAPHITE_STORE_RATES 0x01
+#define GRAPHITE_SEPARATE_INSTANCES 0x02
+#define GRAPHITE_ALWAYS_APPEND_DS 0x04
+
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,
- _Bool store_rates);
+ unsigned int flags);
#endif /* UTILS_FORMAT_GRAPHITE_H */
diff --git a/src/write_graphite.c b/src/write_graphite.c
index 2ae30efe2ca179b0fd13cfafe5914f5a031b14ff..8ae15ba0c5a2536f332b5de0358a7a13ed127d56 100644 (file)
--- a/src/write_graphite.c
+++ b/src/write_graphite.c
char *postfix;
char escape_char;
- _Bool store_rates;
- _Bool separate_instances;
- _Bool always_append_ds;
+ unsigned int format_flags;
char send_buf[WG_SEND_BUF_SIZE];
size_t send_buf_free;
memset (buffer, 0, sizeof (buffer));
status = format_graphite (buffer, sizeof (buffer), ds, vl,
- cb->prefix, cb->postfix, cb->escape_char, cb->store_rates);
+ cb->prefix, cb->postfix, cb->escape_char, cb->format_flags);
if (status != 0) /* error message has been printed already. */
return (status);
cb->prefix = NULL;
cb->postfix = NULL;
cb->escape_char = WG_DEFAULT_ESCAPE;
- cb->store_rates = 1;
+ cb->format_flags = GRAPHITE_STORE_RATES;
pthread_mutex_init (&cb->send_lock, /* attr = */ NULL);
else if (strcasecmp ("Postfix", child->key) == 0)
cf_util_get_string (child, &cb->postfix);
else if (strcasecmp ("StoreRates", child->key) == 0)
- cf_util_get_boolean (child, &cb->store_rates);
+ cf_util_get_flag (child, &cb->format_flags,
+ GRAPHITE_STORE_RATES);
else if (strcasecmp ("SeparateInstances", child->key) == 0)
- cf_util_get_boolean (child, &cb->separate_instances);
+ cf_util_get_flag (child, &cb->format_flags,
+ GRAPHITE_SEPARATE_INSTANCES);
else if (strcasecmp ("AlwaysAppendDS", child->key) == 0)
- cf_util_get_boolean (child, &cb->always_append_ds);
+ cf_util_get_flag (child, &cb->format_flags,
+ GRAPHITE_ALWAYS_APPEND_DS);
else if (strcasecmp ("EscapeCharacter", child->key) == 0)
config_set_char (&cb->escape_char, child);
else