Fixes Github issue #214.
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)
#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");
#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 */
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