<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, Feb 27, 2017 at 10:50 PM Pavel V. <<a href="mailto:pavel2000@ngs.ru">pavel2000@ngs.ru</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br class="gmail_msg">
How do you implemented read callback registering?<br class="gmail_msg">
<br class="gmail_msg">
If you call plugin_register (TYPE_READ, "FooBar", "foobar_read") twice with same<br class="gmail_msg">
plugin name, the plugin will be registered only once (with warning at logs)!<br class="gmail_msg">
<br class="gmail_msg"></blockquote><div><br></div><div>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? </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
There is two ways to get your needs:<br class="gmail_msg">
<br class="gmail_msg">
1) Register perl plugin multiple times with different plugin names, like this:<br class="gmail_msg">
<br class="gmail_msg">
plugin_register (TYPE_READ, "FooBar/$hostname", "foobar_read");<br class="gmail_msg">
<br class="gmail_msg">
I.e. a separate registration for each host/thread.<br class="gmail_msg">
<br class="gmail_msg">
That will be equal to plugin_register_complex_read() of C plugins, just without<br class="gmail_msg">
'userdata'.<br class="gmail_msg">
<br class="gmail_msg">
To distinguish hosts, you may try to use sub AUTOLOAD {...} and $AUTOLOAD variable:<br class="gmail_msg">
<br class="gmail_msg">
our $AUTOLOAD;<br class="gmail_msg">
sub AUTOLOAD {<br class="gmail_msg">
#print $AUTOLOAD."\n"; #Expected output: package::foobar_read_$hostname<br class="gmail_msg">
<br class="gmail_msg">
if ($AUTOLOAD =~ /\:\:foobar_read_(.*)$/) {<br class="gmail_msg">
foobar_read($1);<br class="gmail_msg">
}<br class="gmail_msg">
else {<br class="gmail_msg">
die;<br class="gmail_msg">
}<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
#Many times, for each $hostname<br class="gmail_msg">
plugin_register (TYPE_READ, "FooBar/$hostname", "foobar_read_$hostname");<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
OR pregenerate required subs:<br class="gmail_msg">
<br class="gmail_msg">
#Many times, for each $hostname<br class="gmail_msg">
eval "sub foobar_read_$hostname { foobar_read('$hostname');}";<br class="gmail_msg">
plugin_register (TYPE_READ, "FooBar/$hostname", "foobar_read_$hostname");<br class="gmail_msg">
<br class="gmail_msg">
(I don't checked these under Collectd ever)<br class="gmail_msg">
<br class="gmail_msg">
In this case, your threads can be polled by Collectd in parallel,<br class="gmail_msg">
simultaneously, which can be better for performance / if there is many hosts<br class="gmail_msg">
polled.<br class="gmail_msg">
<br class="gmail_msg">
Preferred way, IMHO.<br class="gmail_msg"></blockquote><div><br></div><div>i dont know my hostname before i get called by the config callback (as my hostnames are stored there.) </div><div><br></div><div>so i attempted to register the read callback from within the config callback, which gives me this: </div><div><br></div><div>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"</div><div><br></div><div>I assume registering a callback has to happen earlier?</div><div><br></div><div><br></div></div></div>