summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 218dbd0)
raw | patch | inline | side by side (parent: 218dbd0)
author | Florian Forster <octo@collectd.org> | |
Sat, 25 May 2013 08:57:58 +0000 (10:57 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Sat, 25 May 2013 08:57:58 +0000 (10:57 +0200) |
When enabled, <Plugin ...> blocks will automatically load plugins.
Thanks to Tim Bunce for suggesting this!
Github: #333
Thanks to Tim Bunce for suggesting this!
Github: #333
src/collectd.conf.in | patch | blob | history | |
src/collectd.conf.pod | patch | blob | history | |
src/configfile.c | patch | blob | history |
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index b817e8c4205bf9cc94cbeb9abe1cf00a1be5d406..9e383d01934419b68b6f40df35793b198e9be50d 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
#PluginDir "@libdir@/@PACKAGE_NAME@"
#TypesDB "@prefix@/share/@PACKAGE_NAME@/types.db"
+#----------------------------------------------------------------------------#
+# When enabled, plugins are loaded automatically with the default options #
+# when an appropriate <Plugin ...> 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 326944f152758cad2620313f7bcdd92d485c4ce1..bd4b2b9ba14c3368c62f59cf05bffc5da36ffa72 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
=item B<LoadPlugin> I<Plugin>
-Loads the plugin I<Plugin>. There must be at least one such line or B<collectd>
-will be mostly useless.
-
-Starting with collectd 4.9, this may also be a block in which further options
-affecting the behavior of B<LoadPlugin> may be specified. The following
-options are allowed inside a B<LoadPlugin> block:
-
- <LoadPlugin perl>
- Globals true
- Interval 10
- </LoadPlugin>
+Loads the plugin I<Plugin>. This is required to load plugins, unless the
+B<AutoLoadPlugin> option is enabled (see below). Without any loaded plugins,
+I<collectd> will be mostly useless.
Only the first B<LoadPlugin> statement or block for a given plugin name has any
effect. This is useful when you want to split up the configuration into smaller
different intervals, only one of them (the first one encountered) will take
effect and all others will be silently ignored.
+B<LoadPlugin> may either be a simple configuration I<statement> or a I<block>
+with additional options, affecting the behavior of B<LoadPlugin>. A simple
+statement looks like this:
+
+ LoadPlugin "cpu"
+
+Options inside a B<LoadPlugin> block can override default settings and
+influence the way plugins are loaded, e.g.:
+
+ <LoadPlugin perl>
+ Globals true
+ Interval 60
+ </LoadPlugin>
+
+The following options are valid inside B<LoadPlugin> blocks:
+
=over 4
=item B<Globals> B<true|false>
=back
+=item B<AutoLoadPlugin> B<false>|B<true>
+
+When set to B<false> (the default), each plugin needs to be loaded explicitly,
+using the B<LoadPlugin> statement documented above. If a
+B<E<lt>PluginE<nbsp>...E<gt>> 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<true>, explicit B<LoadPlugin> statements are not required. Each
+B<E<lt>PluginE<nbsp>...E<gt>> block acts as if it was immediately preceded by a
+B<LoadPlugin> statement. B<LoadPlugin> statements are still required for
+plugins that don't provide any configuration, e.g. the I<Load plugin>.
+
=item B<Include> I<Path> [I<pattern>]
If I<Path> points to a file, includes that file. If I<Path> points to a
diff --git a/src/configfile.c b/src/configfile.c
index e680aba771bf13b3b0bf76582f0019e1a78779f2..876ee23ee71c8c33d2f230170bf94147a6012404 100644 (file)
--- a/src/configfile.c
+++ b/src/configfile.c
{"ReadThreads", NULL, "5"},
{"WriteThreads", NULL, "5"},
{"Timeout", NULL, "2"},
+ {"AutoLoadPlugin", NULL, "false"},
{"PreCacheChain", NULL, "PreCache"},
{"PostCacheChain", NULL, "PostCache"}
};
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)
{