in Geeky

Collectd Python plugin

One of the most interesting development in collectd recently (4.9) would have to be the availability of a Python binding. You can find the man page here with some samples.

Another interesting feature available with collectd plugins is the availability to overwrite the `hostname`. This opens up a whole new page to collectd, including what I’m attempting right now which is active checks.

In any case, a sample python plugin which overwrites the `hostname` would look like so:

# Sample Python module to use python plugin 

import collectd

#== Our Own Functions go here: ==#
def configer(ObjConfiguration):
   collectd.debug('Configuring Stuff') 

def initer():
    collectd.debug('initing stuff')

def reader(input_data=None):
    metric = collectd.Values();
    metric.plugin = 'python_plugin_test'
    metric.type = 'gauge'
    metric.values = [100]
    metric.host = 'OverwritenHostname'
    metric.dispatch()

#== Hook Callbacks, Order is important! ==#
collectd.register_config(configer)
collectd.register_init(initer)
collectd.register_read(reader)

Lets assume a few things here:

1. Collectd installation:
/opt/collectd/current/,

2. python plugins
/opt/collectd/current/share/python/.

3. plugin file python_plugin_test.py will be in
/opt/collectd/current/share/python/python_plugin_test.py

The relevant corresponding config in /opt/collectd/current/etc/collectd.conf would look something like:

LoadPlugin python
<Plugin python>
  ModulePath "/opt/collectd/current/share/python/"
  LogTraces true
  Interactive false
  Import python_plugin_test
  <Module python_plugin_test>
    Test "This" "are" "the" "inputs"
  </Module>
</Plugin>

Dont forget to test your plugins by running sbin/collectd -C  etc/collectd.conf -T If this causes nothing to be printed on the STDOUT, that means your plugins are good.

Related Posts

Written By:

Add a Comment