[collectd] Dynamic interval values for Python Plugins
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:
res = apt_check()
upgrades = collectd.Values(plugin=NAME, type='apt')
upgrades.values = [ res, res ]
#collectd.info("Apt-Check %s %s " % (res, res))
if(res > 0 or res > 0):
callback_id = collectd.register_read(read_callback, SHORT_INTERVAL)
callback_id = collectd.register_read(read_callback, INTERVAL)
In my read callback, after I get the number of upgrades, if there are
upgrades (res or res > 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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the collectd