From: Florian Forster Date: Tue, 29 Jan 2013 09:22:41 +0000 (+0100) Subject: write_graphite plugin: Change blocks to blocks. X-Git-Tag: collectd-5.3.0~45 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c257598b7e1726349561aa3c3bf10177ac9db883;p=collectd.git write_graphite plugin: Change blocks to blocks. Many other write plugins, e.g. write_{mongodb,redis,riemann} use the syntax. This adds code to handle this syntax as well. While the documentation doesn't mention it, the old syntax (without a name) is still supported for backwards compatibility. --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 699c0e0a..8744b21a 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1021,15 +1021,15 @@ # # -# +# # Host "localhost" # Port "2003" # Prefix "collectd" # Postfix "collectd" -# StoreRates false +# StoreRates true # AlwaysAppendDS false # EscapeCharacter "_" -# +# # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index aa2871d8..62ecad44 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -5372,13 +5372,16 @@ minimize the number of network packets. Synopsis: - + Host "localhost" Port "2003" Prefix "collectd" - + +The configuration consists of one or more EBEIE +blocks. Inside the B blocks, the following options are recognized: + =over 4 =item B I
diff --git a/src/write_graphite.c b/src/write_graphite.c index 2ae30efe..1d504100 100644 --- a/src/write_graphite.c +++ b/src/write_graphite.c @@ -79,6 +79,8 @@ struct wg_callback { int sock_fd; + char *name; + char *node; char *service; char *prefix; @@ -244,6 +246,7 @@ static void wg_callback_free (void *data) close(cb->sock_fd); cb->sock_fd = -1; + sfree(cb->name); sfree(cb->node); sfree(cb->service); sfree(cb->prefix); @@ -414,7 +417,7 @@ static int config_set_char (char *dest, return (0); } -static int wg_config_carbon (oconfig_item_t *ci) +static int wg_config_node (oconfig_item_t *ci) { struct wg_callback *cb; user_data_t user_data; @@ -429,6 +432,7 @@ static int wg_config_carbon (oconfig_item_t *ci) } memset (cb, 0, sizeof (*cb)); cb->sock_fd = -1; + cb->name = NULL; cb->node = NULL; cb->service = NULL; cb->prefix = NULL; @@ -436,6 +440,17 @@ static int wg_config_carbon (oconfig_item_t *ci) cb->escape_char = WG_DEFAULT_ESCAPE; cb->store_rates = 1; + /* FIXME: Legacy configuration syntax. */ + if (strcasecmp ("Carbon", ci->key) != 0) + { + int status = cf_util_get_string (ci, &cb->name); + if (status != 0) + { + wg_callback_free (cb); + return (status); + } + } + pthread_mutex_init (&cb->send_lock, /* attr = */ NULL); for (i = 0; i < ci->children_num; i++) @@ -465,9 +480,14 @@ static int wg_config_carbon (oconfig_item_t *ci) } } - ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s/%s", - cb->node != NULL ? cb->node : WG_DEFAULT_NODE, - cb->service != NULL ? cb->service : WG_DEFAULT_SERVICE); + /* FIXME: Legacy configuration syntax. */ + if (cb->name == NULL) + ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s/%s", + cb->node != NULL ? cb->node : WG_DEFAULT_NODE, + cb->service != NULL ? cb->service : WG_DEFAULT_SERVICE); + else + ssnprintf (callback_name, sizeof (callback_name), "write_graphite/%s", + cb->name); memset (&user_data, 0, sizeof (user_data)); user_data.data = cb; @@ -488,8 +508,11 @@ static int wg_config (oconfig_item_t *ci) { oconfig_item_t *child = ci->children + i; - if (strcasecmp ("Carbon", child->key) == 0) - wg_config_carbon (child); + if (strcasecmp ("Node", child->key) == 0) + wg_config_node (child); + /* FIXME: Remove this legacy mode in version 6. */ + else if (strcasecmp ("Carbon", child->key) == 0) + wg_config_node (child); else { ERROR ("write_graphite plugin: Invalid configuration "