From: Florian Forster Date: Sat, 25 May 2013 08:57:58 +0000 (+0200) Subject: src/configfile.c: Add the "AutoLoadPlugin" option. X-Git-Tag: collectd-5.4.0~37 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1c65936918f096a0730a4130a363393febcf163b;p=collectd.git src/configfile.c: Add the "AutoLoadPlugin" option. When enabled, blocks will automatically load plugins. Thanks to Tim Bunce for suggesting this! Github: #333 --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index b817e8c4..9e383d01 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -18,6 +18,13 @@ #TypesDB "@prefix@/share/@PACKAGE_NAME@/types.db" #----------------------------------------------------------------------------# +# When enabled, plugins are loaded automatically with the default options # +# when an appropriate block is encountered. # +# Disabled by default. # +#----------------------------------------------------------------------------# +#AutoLoadPlugin false + +#----------------------------------------------------------------------------# # Interval at which to query values. This may be overwritten on a per-plugin # # base by using the 'Interval' option of the LoadPlugin block: # # # diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 326944f1..bd4b2b9b 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -68,17 +68,9 @@ directory for the daemon. =item B I -Loads the plugin I. There must be at least one such line or B -will be mostly useless. - -Starting with collectd 4.9, this may also be a block in which further options -affecting the behavior of B may be specified. The following -options are allowed inside a B block: - - - Globals true - Interval 10 - +Loads the plugin I. This is required to load plugins, unless the +B option is enabled (see below). Without any loaded plugins, +I will be mostly useless. Only the first B statement or block for a given plugin name has any effect. This is useful when you want to split up the configuration into smaller @@ -88,6 +80,22 @@ you have multiple conflicting B blocks, e.g. when they specify different intervals, only one of them (the first one encountered) will take effect and all others will be silently ignored. +B may either be a simple configuration I or a I +with additional options, affecting the behavior of B. A simple +statement looks like this: + + LoadPlugin "cpu" + +Options inside a B block can override default settings and +influence the way plugins are loaded, e.g.: + + + Globals true + Interval 60 + + +The following options are valid inside B blocks: + =over 4 =item B B @@ -117,6 +125,19 @@ interval, that setting will take precedence. =back +=item B B|B + +When set to B (the default), each plugin needs to be loaded explicitly, +using the B statement documented above. If a +BPluginE...E> block is encountered and no configuration +handling callback for this plugin has been registered, a warning is logged and +the block is ignored. + +When set to B, explicit B statements are not required. Each +BPluginE...E> block acts as if it was immediately preceded by a +B statement. B statements are still required for +plugins that don't provide any configuration, e.g. the I. + =item B I [I] If I points to a file, includes that file. If I points to a diff --git a/src/configfile.c b/src/configfile.c index e680aba7..876ee23e 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -110,6 +110,7 @@ static cf_global_option_t cf_global_options[] = {"ReadThreads", NULL, "5"}, {"WriteThreads", NULL, "5"}, {"Timeout", NULL, "2"}, + {"AutoLoadPlugin", NULL, "false"}, {"PreCacheChain", NULL, "PreCache"}, {"PostCacheChain", NULL, "PostCache"} }; @@ -379,6 +380,19 @@ static int dispatch_block_plugin (oconfig_item_t *ci) name = ci->values[0].value.string; + if (IS_TRUE (global_option_get ("AutoLoadPlugin"))) + { + int status; + + status = plugin_load (name, /* flags = */ 0); + if (status != 0) + { + ERROR ("Automatically loading plugin \"%s\" failed " + "with status %i.", name, status); + return (status); + } + } + /* Check for a complex callback first */ for (cb = complex_callback_head; cb != NULL; cb = cb->next) {