<div dir="ltr">hi, all<br><br><font> <span tabindex="-1" id="result_box" class="" lang="en"><span class="">In</span> <span class="">documentation</span> <span class="">introduced</span> <span class="">the init function in python plugin</span></span>: </font><br>
<div style="margin-left:40px">These are called once after loading the module and before any
calls to the read and write functions. It should be used to initialize the
internal state of the plugin (e. g. open sockets, ...).<br></div><br><br><div><div><font> <span tabindex="-1" id="result_box" class="" lang="en"><span class="">But</span> <span class="">in the use of</span> <span class="">found the init function only before read function, start with the write plugin at the same time.<br>
So i write a test </span></span>plugin to <span tabindex="-1" id="result_box" class="" lang="en"><span class="">verify,</span></span> plugin code like that:</font><br><br><div style="margin-left:40px"><span style="font-family:courier new,monospace">PLUGIN = 'COLLECTD_WRITE_OPENTSDB'<br>
<br>METRIC_PAYLOAD = list()<br>ADDRESS2IDC_DATA = dict()<br><br>QUEUE = Queue('opentsdb', connection=Redis())<br><br><br>def init_callback():<br><br> global ADDRESS2IDC_DATA<br><br> <a href="http://logger.info">logger.info</a>('Initialization plugin %s, frequency is %s.' % (PLUGIN, config.get('MASTER', 'REPORT_STATUS_INTERVAL')))<br>
<br> ADDRESS2IDC_DATA = renew_address2idc_data(renew=True)<br><br> <a href="http://logger.info">logger.info</a>('Initialization plugin %s successful' % PLUGIN)<br><br><br>def read_callback():<br><br> <a href="http://logger.info">logger.info</a>('Plugin %s: Enter the read cycle' % PLUGIN)<br>
<br><br>def write_callback(metric):<br><br> <a href="http://logger.info">logger.info</a>('Plugin %s: Enter the write cycle' % PLUGIN)<br><br><br>collectd.register_init(init_callback)<br>collectd.register_read(read_callback, interval=config.getint('MASTER', 'REPORT_STATUS_INTERVAL'))<br>
collectd.register_write(write_callback)<br></span></div><br><div><font> And </font><span tabindex="-1" id="result_box" class="" lang="en"><span class=""><font>the actual colletcd.log is like that:</font><br><br></span></span><div style="margin-left:40px">
<span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:23] Initialization plugin COLLECTD_WRITE_OPENTSDB, frequency is 120.</span></span><br><span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:23] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle</span></span><br>
<span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:23] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle</span></span><br><span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:23] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle</span></span><br>
<span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:23] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle</span></span><br><span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:23] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle</span></span><br>
<span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:24] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle</span></span><br><span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:24] RENEW_ADDRESS2IDC_DATA: Update address2idc data successful, contains 23582 records</span></span><br>
<span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:24] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle</span></span><br><span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:24] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle</span></span><br>
<span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:24] Initialization plugin COLLECTD_WRITE_OPENTSDB successful</span></span><br><span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:24] Plugin COLLECTD_WRITE_OPENTSDB: Enter the read cycle</span></span><br>
<span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:24] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle</span></span><br><span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:24] Unhandled python exception in write callback: AttributeError: 'NoneType' object has no attribute 'get'</span></span><br>
<span tabindex="-1" id="result_box" class="" lang="en"><span class="">[2014-06-04 18:14:24] Initialization complete, entering read-loop.</span></span><br></div><div style="margin-left:40px"><span tabindex="-1" id="result_box" class="" lang="en"><span class=""></span></span></div>
<br><font> <span tabindex="-1" id="result_box" class="" lang="en"><span class="">Environment is RHEL6.3 and collectd-4.10.9-1.el6<br><br></span></span><span tabindex="-1" id="result_box" class="" lang="en"><span class=""> Do I</span> <span class="">use</span> <span class="">the wrong way</span></span><span tabindex="-1" id="result_box" class="" lang="en"><span class=""></span></span>, more thanks.</font><br>
<br clear="all"><div><font><span style="font-family:courier new,monospace;color:rgb(153,153,153)">Nothing is Sound.</span></font></div>
</div></div></div></div>