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] = 'OverwritenHostname'

#== Hook Callbacks, Order is important! ==#

Lets assume a few things here:

1. Collectd installation:

2. python plugins

3. plugin file will be in

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"

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.

label, , ,

About the author

Add a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.