[collectd] question with init function in python plugin
Ruoyan Wang
kid.xiyang at gmail.com
Wed Jun 4 12:38:03 CEST 2014
hi, all
In documentation introduced the init function in python plugin:
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, ...).
But in the use of found the init function only before read function,
start with the write plugin at the same time.
So i write a test plugin to verify, plugin code like that:
PLUGIN = 'COLLECTD_WRITE_OPENTSDB'
METRIC_PAYLOAD = list()
ADDRESS2IDC_DATA = dict()
QUEUE = Queue('opentsdb', connection=Redis())
def init_callback():
global ADDRESS2IDC_DATA
logger.info('Initialization plugin %s, frequency is %s.' % (PLUGIN,
config.get('MASTER', 'REPORT_STATUS_INTERVAL')))
ADDRESS2IDC_DATA = renew_address2idc_data(renew=True)
logger.info('Initialization plugin %s successful' % PLUGIN)
def read_callback():
logger.info('Plugin %s: Enter the read cycle' % PLUGIN)
def write_callback(metric):
logger.info('Plugin %s: Enter the write cycle' % PLUGIN)
collectd.register_init(init_callback)
collectd.register_read(read_callback, interval=config.getint('MASTER',
'REPORT_STATUS_INTERVAL'))
collectd.register_write(write_callback)
And the actual colletcd.log is like that:
[2014-06-04 18:14:23] Initialization plugin COLLECTD_WRITE_OPENTSDB,
frequency is 120.
[2014-06-04 18:14:23] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle
[2014-06-04 18:14:23] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle
[2014-06-04 18:14:23] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle
[2014-06-04 18:14:23] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle
[2014-06-04 18:14:23] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle
[2014-06-04 18:14:24] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle
[2014-06-04 18:14:24] RENEW_ADDRESS2IDC_DATA: Update address2idc data
successful, contains 23582 records
[2014-06-04 18:14:24] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle
[2014-06-04 18:14:24] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle
[2014-06-04 18:14:24] Initialization plugin COLLECTD_WRITE_OPENTSDB
successful
[2014-06-04 18:14:24] Plugin COLLECTD_WRITE_OPENTSDB: Enter the read cycle
[2014-06-04 18:14:24] Plugin COLLECTD_WRITE_OPENTSDB: Enter the write cycle
[2014-06-04 18:14:24] Unhandled python exception in write callback:
AttributeError: 'NoneType' object has no attribute 'get'
[2014-06-04 18:14:24] Initialization complete, entering read-loop.
Environment is RHEL6.3 and collectd-4.10.9-1.el6
Do I use the wrong way, more thanks.
Nothing is Sound.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20140604/ce717331/attachment-0001.html>
More information about the collectd
mailing list