[collectd] Dynamic interval values for Python Plugins
Horacio Sanson
hsanson at gmail.com
Thu Jul 17 10:36:02 CEST 2014
I am writing a python plugin that checks the number of available upgrades
and security upgrades on Debian servers (based on apt-check tool).
The thing is that I want this check to be executed once every day unless
there are upgrades available in which case I want to reduce the interval to
a lower value. Once the upgrades are installed I want the interval to
change back to once a day.
This is what I tried in my plugin:
def read_callback():
global callback_id
res = apt_check()
upgrades = collectd.Values(plugin=NAME, type='apt')
upgrades.values = [ res[0], res[1] ]
upgrades.dispatch()
#collectd.info("Apt-Check %s %s " % (res[0], res[1]))
if(res[0] > 0 or res[1] > 0):
collectd.unregister_read(callback_id)
callback_id = collectd.register_read(read_callback, SHORT_INTERVAL)
else:
collectd.unregister_read(callback_id)
callback_id = collectd.register_read(read_callback, INTERVAL)
In my read callback, after I get the number of upgrades, if there are
upgrades (res[0] or res[1] > 0) I unregister the read callback and register
it again with a shorter iterval. If there are no upgrades I register it
with a large interval (e.g. 24 hours).
My questions are:
- Is is necessary to unregister the callback each time? or is the
register_read method indemponent and can be called multiple times without
causing memory leaks?
- It seems that the interval variable in the register_read method is
ignored. If I un-comment the info call I can see the read callback is
invoked at increasing intervals starting from 3 secs. No matter what are
the values of INTERVAL and SHORT_INTERVAL.
- Is there a better way in collectd to support dynamic intervals that
depend on the values being monitored?
regards,
Horacio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20140717/880b5dd3/attachment.html>
More information about the collectd
mailing list