[collectd] perl plugin: callback only for one of the thread
Andreas Schuldei
andreas at schuldei.org
Tue Feb 28 11:31:12 CET 2017
On Mon, Feb 27, 2017 at 10:50 PM Pavel V. <pavel2000 at ngs.ru> wrote:
>
> How do you implemented read callback registering?
>
> If you call plugin_register (TYPE_READ, "FooBar", "foobar_read") twice
> with same
> plugin name, the plugin will be registered only once (with warning at
> logs)!
>
>
indeed i registered the read callback twice with the same plugin and
function name. doh. I didn't see any warning in the logs. what should it
say?
> There is two ways to get your needs:
>
> 1) Register perl plugin multiple times with different plugin names, like
> this:
>
> plugin_register (TYPE_READ, "FooBar/$hostname", "foobar_read");
>
> I.e. a separate registration for each host/thread.
>
> That will be equal to plugin_register_complex_read() of C plugins, just
> without
> 'userdata'.
>
> To distinguish hosts, you may try to use sub AUTOLOAD {...} and $AUTOLOAD
> variable:
>
> our $AUTOLOAD;
> sub AUTOLOAD {
> #print $AUTOLOAD."\n"; #Expected output:
> package::foobar_read_$hostname
>
> if ($AUTOLOAD =~ /\:\:foobar_read_(.*)$/) {
> foobar_read($1);
> }
> else {
> die;
> }
> }
>
> #Many times, for each $hostname
> plugin_register (TYPE_READ, "FooBar/$hostname", "foobar_read_$hostname");
>
>
> OR pregenerate required subs:
>
> #Many times, for each $hostname
> eval "sub foobar_read_$hostname { foobar_read('$hostname');}";
> plugin_register (TYPE_READ, "FooBar/$hostname", "foobar_read_$hostname");
>
> (I don't checked these under Collectd ever)
>
> In this case, your threads can be polled by Collectd in parallel,
> simultaneously, which can be better for performance / if there is many
> hosts
> polled.
>
> Preferred way, IMHO.
>
i dont know my hostname before i get called by the config callback (as my
hostnames are stored there.)
so i attempted to register the read callback from within the config
callback, which gives me this:
Feb 28 11:13:54 david collectd[31153]: perl: Execution of callback
"Collectd::Plugins::OneWireCtlr::my_read_192.168.178.117" failed: unknown
callback "Collectd::Plugins::OneWireCtlr::my_read_192.168.178.117"
I assume registering a callback has to happen earlier?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20170228/69216348/attachment.html>
More information about the collectd
mailing list