[collectd] perl plugin: callback only for one of the thread
Pavel V.
pavel2000 at ngs.ru
Tue Feb 28 12:15:40 CET 2017
Hi, Andreas.
> 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?
I assume you use collectd-5.7. It is true?
The reporting function call looks like:
WARNING ("The read function \"%s\" is already registered. "
"Check for duplicate \"LoadPlugin\" lines "
"in your configuration!", $pluginname);
> i dont know my hostname before i get called by the config callback (as my hostnames are stored there.)
That is expected and correct.
> 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 think that message comes from callback call, not from registration.
Is that function exists in package / added by eval() or you try to use
AUTOLOAD?
> I assume registering a callback has to happen earlier?
Just tried:
---
<Plugin perl>
IncludeDir "/opt/collectd/share/perl5"
BaseName "Collectd::Plugins"
LoadPlugin "FooBar"
<Plugin FooBar>
Foo "Bar"
</Plugin>
</Plugin>
---
package Collectd::Plugins::FooBar;
use strict;
use warnings;
use Collectd qw( :all );
plugin_register (TYPE_CONFIG, "FooBar", "foobar_config");
sub foobar_config {
my $config = shift;
plugin_register (TYPE_READ, "FooBar", "foobar_read");
plugin_register (TYPE_READ, "FooBar/1", "foobar_read_1");
return 1;
}
sub foobar_read { ... }; #Works.
#sub foobar_read_1 { ... }; #Works too.
our $AUTOLOAD;
sub AUTOLOAD {
ERROR ("AUTOLOAD $AUTOLOAD"); #Called as expected and reports to log:
#AUTOLOAD Collectd::Plugins::FooBar::foobar_read_1
}
All works as expected. Notice again: I use collectd-5.7, which has new implementation of
perl plugins registration. collectd-5.6 is differ.
--
Regards,
Pavel mailto:pavel2000 at ngs.ru
More information about the collectd
mailing list