From afecba06803e867b17a46f093495c9b6c7a028fa Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Sun, 24 Apr 2016 20:54:29 +0600 Subject: [PATCH] memcachec plugin: Allow custom plugin name for each Page block --- src/collectd.conf.pod | 6 ++++++ src/memcachec.c | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index f99fe77f..91ff7416 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -3542,6 +3542,7 @@ Synopsis of the configuration: Server "localhost" Key "page_key" + PluginName "plugin_name" Regex "(\\d+) bytes sent" DSType CounterAdd @@ -3569,6 +3570,11 @@ B block. When connected to the memcached server, asks for the page I. +=item B I + +Use I as the plugin name when submitting values. +Defaults to 'memcachec'. + =item EBE Match blocks define which strings to look for and how matches substrings are diff --git a/src/memcachec.c b/src/memcachec.c index c2147fd5..965aa653 100644 --- a/src/memcachec.c +++ b/src/memcachec.c @@ -51,6 +51,7 @@ struct web_page_s; typedef struct web_page_s web_page_t; struct web_page_s /* {{{ */ { + char *plugin_name; char *instance; char *server; @@ -94,6 +95,7 @@ static void cmc_web_page_free(web_page_t *wp) /* {{{ */ memcached_free(wp->memc); wp->memc = NULL; + sfree(wp->plugin_name); sfree(wp->instance); sfree(wp->server); sfree(wp->key); @@ -302,6 +304,8 @@ static int cmc_config_add_page(oconfig_item_t *ci) /* {{{ */ status = cmc_config_add_string("Server", &page->server, child); else if (strcasecmp("Key", child->key) == 0) status = cmc_config_add_string("Key", &page->key, child); + else if (strcasecmp("PluginName", child->key) == 0) + status = cmc_config_add_string("PluginName", &page->plugin_name, child); else if (strcasecmp("Match", child->key) == 0) /* Be liberal with failing matches => don't set `status'. */ cmc_config_add_match(page, child); @@ -407,7 +411,8 @@ static void cmc_submit(const web_page_t *wp, const web_match_t *wm, /* {{{ */ vl.values = &value; vl.values_len = 1; - sstrncpy(vl.plugin, "memcachec", sizeof(vl.plugin)); + sstrncpy(vl.plugin, (wp->plugin_name != NULL) ? wp->plugin_name : "memcachec", + sizeof (vl.plugin)); sstrncpy(vl.plugin_instance, wp->instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, wm->type, sizeof(vl.type)); sstrncpy(vl.type_instance, wm->instance, sizeof(vl.type_instance)); -- 2.11.0