summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: acd2fa4)
raw | patch | inline | side by side (parent: acd2fa4)
author | Florian Forster <octo@collectd.org> | |
Tue, 7 Feb 2012 17:19:20 +0000 (18:19 +0100) | ||
committer | Florian Forster <octo@collectd.org> | |
Tue, 7 Feb 2012 17:19:20 +0000 (18:19 +0100) |
Don't append DS name by default, except when there is more than one DS.
The "AlwaysAppendDS" option can be used to force the plugin to always
append the DS.
Change-Id: I0221bef49375e3b5c5de99bb8f5a9cd641b696c3
The "AlwaysAppendDS" option can be used to force the plugin to always
append the DS.
Change-Id: I0221bef49375e3b5c5de99bb8f5a9cd641b696c3
src/collectd.conf.pod | patch | blob | history | |
src/write_graphite.c | patch | blob | history |
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 64ef7f2e9e49db053737dee5da9764bc1270797c..18b7378347bca12fe1c583e833044aecd71f49fe 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
default) counter values are stored as is, i.E<nbsp>e. as an increasing integer
number.
+=item B<AlwaysAppendDS> B<false>|B<true>
+
+If set the B<true>, append the name of the I<Data Source> (DS) to the "metric"
+identifier. If set to B<false> (the default), this is only done when there is
+more than one DS.
+
=back
=head2 Plugin C<write_http>
diff --git a/src/write_graphite.c b/src/write_graphite.c
index fca40d1a478fc48639686185edb2e4a8491ea918..2e4af22db16b05425ccbd9a02a1cc7ea3d03a983 100644 (file)
--- a/src/write_graphite.c
+++ b/src/write_graphite.c
#include <sys/socket.h>
#include <netdb.h>
-#ifndef WG_FORMAT_NAME
-#define WG_FORMAT_NAME(ret, ret_len, vl, cb, ds_name) \
- wg_format_name (ret, ret_len, (vl)->host, \
- (vl)->plugin, (vl)->plugin_instance, \
- (vl)->type, (vl)->type_instance, \
- (cb)->prefix, (cb)->postfix, \
- ds_name, (cb)->escape_char)
-#endif
-
#ifndef WG_DEFAULT_NODE
# define WG_DEFAULT_NODE "localhost"
#endif
char escape_char;
_Bool store_rates;
+ _Bool always_append_ds;
char send_buf[WG_SEND_BUF_SIZE];
size_t send_buf_free;
}
static int wg_format_name (char *ret, int ret_len,
- const char *hostname,
- const char *plugin, const char *plugin_instance,
- const char *type, const char *type_instance,
- const char *prefix, const char *postfix,
- const char *ds_name, char escape_char)
+ const value_list_t *vl,
+ const struct wg_callback *cb,
+ const char *ds_name)
{
- char n_hostname[DATA_MAX_NAME_LEN];
+ char n_host[DATA_MAX_NAME_LEN];
char n_plugin[DATA_MAX_NAME_LEN];
char n_plugin_instance[DATA_MAX_NAME_LEN];
char n_type[DATA_MAX_NAME_LEN];
char n_type_instance[DATA_MAX_NAME_LEN];
- int status;
- assert (hostname != NULL);
- assert (plugin != NULL);
- assert (type != NULL);
- assert (ds_name != NULL);
+ char *prefix;
+ char *postfix;
+
+ char tmp_plugin[2 * DATA_MAX_NAME_LEN + 1];
+ char tmp_type[2 * DATA_MAX_NAME_LEN + 1];
+ prefix = cb->prefix;
if (prefix == NULL)
prefix = "";
+ postfix = cb->postfix;
if (postfix == NULL)
postfix = "";
- wg_copy_escape_part (n_hostname, hostname,
- sizeof (n_hostname), escape_char);
- wg_copy_escape_part (n_plugin, plugin,
- sizeof (n_plugin), escape_char);
- wg_copy_escape_part (n_plugin_instance, plugin_instance,
- sizeof (n_plugin_instance), escape_char);
- wg_copy_escape_part (n_type, type,
- sizeof (n_type), escape_char);
- wg_copy_escape_part (n_type_instance, type_instance,
- sizeof (n_type_instance), escape_char);
-
- if (n_plugin_instance[0] == '\0')
- {
- if (n_type_instance[0] == '\0')
- {
- status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s",
- prefix, n_hostname, postfix, n_plugin, n_type, ds_name);
- }
- else
- {
- status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s-%s.%s",
- prefix, n_hostname, postfix, n_plugin, n_type,
- n_type_instance, ds_name);
- }
- }
+ wg_copy_escape_part (n_host, vl->host,
+ sizeof (n_host), cb->escape_char);
+ wg_copy_escape_part (n_plugin, vl->plugin,
+ sizeof (n_plugin), cb->escape_char);
+ wg_copy_escape_part (n_plugin_instance, vl->plugin_instance,
+ sizeof (n_plugin_instance), cb->escape_char);
+ wg_copy_escape_part (n_type, vl->type,
+ sizeof (n_type), cb->escape_char);
+ wg_copy_escape_part (n_type_instance, vl->type_instance,
+ sizeof (n_type_instance), cb->escape_char);
+
+ if (n_plugin_instance[0] != '\0')
+ ssnprintf (tmp_plugin, sizeof (tmp_plugin), "%s-%s",
+ n_plugin, n_plugin_instance);
else
- {
- if (n_type_instance[0] == '\0')
- {
- status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s.%s",
- prefix, n_hostname, postfix, n_plugin,
- n_plugin_instance, n_type, ds_name);
- }
- else
- {
- status = ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s-%s.%s",
- prefix, n_hostname, postfix, n_plugin,
- n_plugin_instance, n_type, n_type_instance, ds_name);
- }
- }
+ sstrncpy (tmp_plugin, n_plugin, sizeof (tmp_plugin));
- if ((status < 1) || (status >= ret_len))
- return (-1);
+ if (n_type_instance[0] != '\0')
+ ssnprintf (tmp_type, sizeof (tmp_type), "%s-%s",
+ n_type, n_type_instance);
+ else
+ sstrncpy (tmp_type, n_type, sizeof (tmp_type));
+
+ if (ds_name != NULL)
+ ssnprintf (ret, ret_len, "%s%s%s.%s.%s.%s",
+ prefix, n_host, postfix, tmp_plugin, tmp_type, ds_name);
+ else
+ ssnprintf (ret, ret_len, "%s%s%s.%s.%s",
+ prefix, n_host, postfix, tmp_plugin, tmp_type);
return (0);
}
for (i = 0; i < ds->ds_num; i++)
{
/* Copy the identifier to `key' and escape it. */
- status = WG_FORMAT_NAME (key, sizeof (key), vl, cb, ds->ds[i].name);
+ status = wg_format_name (key, sizeof (key), vl, cb, ds->ds[i].name);
if (status != 0)
{
ERROR ("write_graphite plugin: error with format_name");
else
{
/* Copy the identifier to `key' and escape it. */
- status = WG_FORMAT_NAME (key, sizeof (key), vl, cb, NULL);
+ status = wg_format_name (key, sizeof (key), vl, cb,
+ cb->always_append_ds ? ds->ds[0].name : NULL);
if (status != 0)
{
ERROR ("write_graphite plugin: error with format_name");
int status;
if (user_data == NULL)
- return (-EINVAL);
+ return (EINVAL);
cb = user_data->data;
cf_util_get_string (child, &cb->postfix);
else if (strcasecmp ("StoreRates", child->key) == 0)
cf_util_get_boolean (child, &cb->store_rates);
+ else if (strcasecmp ("AlwaysAppendDS", child->key) == 0)
+ cf_util_get_boolean (child, &cb->always_append_ds);
else if (strcasecmp ("EscapeCharacter", child->key) == 0)
config_set_char (&cb->escape_char, child);
else