From 0b3c11624c7102fd59a16f53fc9165554783652b Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Thu, 21 Sep 2017 13:24:14 +0700 Subject: [PATCH] table: Allow custom plugin name to be reported --- src/collectd.conf.in | 1 + src/collectd.conf.pod | 9 +++++++-- src/table.c | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/collectd.conf.in b/src/collectd.conf.in index fa6c96c1..bbd3a15c 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1343,6 +1343,7 @@ # # +# #Plugin "table" # Instance "slabinfo" # Separator " " # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 379e0838..51f3467a 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -7562,6 +7562,7 @@ filesystem or CSV (comma separated values) files.
+ #Plugin "slab" Instance "slabinfo" Separator " " @@ -7588,10 +7589,14 @@ The following options are available inside a B
block: =over 4 +=item B I + +If specified, I is used as the plugin name when submitting values. +Defaults to B
. + =item B I -If specified, I is used as the plugin instance. So, in the above -example, the plugin name C would be used. If omitted, the +If specified, I is used as the plugin instance. If omitted, the filename of the table is used instead, with all special characters replaced with an underscore (C<_>). diff --git a/src/table.c b/src/table.c index 578e019e..5fb51512 100644 --- a/src/table.c +++ b/src/table.c @@ -55,6 +55,7 @@ typedef struct { typedef struct { char *file; char *sep; + char *plugin_name; char *instance; tbl_result_t *results; @@ -92,6 +93,7 @@ static void tbl_result_clear(tbl_result_t *res) { static void tbl_setup(tbl_t *tbl, char *file) { tbl->file = sstrdup(file); tbl->sep = NULL; + tbl->plugin_name = NULL; tbl->instance = NULL; tbl->results = NULL; @@ -103,6 +105,7 @@ static void tbl_setup(tbl_t *tbl, char *file) { static void tbl_clear(tbl_t *tbl) { sfree(tbl->file); sfree(tbl->sep); + sfree(tbl->plugin_name); sfree(tbl->instance); for (size_t i = 0; i < tbl->results_num; ++i) @@ -256,6 +259,8 @@ static int tbl_config_table(oconfig_item_t *ci) { if (0 == strcasecmp(c->key, "Separator")) tbl_config_set_s(c->key, &tbl->sep, c); + else if (0 == strcasecmp(c->key, "Plugin")) + tbl_config_set_s(c->key, &tbl->plugin_name, c); else if (0 == strcasecmp(c->key, "Instance")) tbl_config_set_s(c->key, &tbl->instance, c); else if (0 == strcasecmp(c->key, "Result")) @@ -367,7 +372,8 @@ static int tbl_result_dispatch(tbl_t *tbl, tbl_result_t *res, char **fields, vl.values = values; vl.values_len = STATIC_ARRAY_SIZE(values); - sstrncpy(vl.plugin, "table", sizeof(vl.plugin)); + sstrncpy(vl.plugin, (tbl->plugin_name != NULL) ? tbl->plugin_name : "table", + sizeof(vl.plugin)); sstrncpy(vl.plugin_instance, tbl->instance, sizeof(vl.plugin_instance)); sstrncpy(vl.type, res->type, sizeof(vl.type)); -- 2.11.0