[collectd] problem with importing collectd python module

Nathan WArd collectd at daork.net
Mon Feb 8 04:27:27 CET 2016


> On 7/02/2016, at 02:54, Pawel Akonom <pawel.akonom at vnomic.com> wrote:
> 
> Hi,
> 
> The problem is with collectd python module - python script can't load it. It can't find it in default python modules path. Is collectd python module included in collectd source code? If so please write with file it is because I couldn't find it. If it's not included in collectd source code from where can I get it? In collectd python plugin documentation there is example with "import collectd" which is loading collectd python module.

Pawel,

The collectd python stuff is a bit confusing, the module that you import is defined in collectd’s python embedding code - see https://github.com/collectd/collectd/blob/42a7c90f4478e98dc970927cfda7ec2e1081f364/src/python.c line 1049 - rather than in a python collectd module that gets loaded in the normal python ways.

This means you can’t run it outside of collectd without modification.

Perhaps it would be possible to move the code in to a python module that can be loaded in the normal python ways, so you can test a module on the command line - I’m not sure.

For testing, you can run your module directly by mocking up the collectd bits, here’s some very stripped down code to give you an idea. Essentially, if the script runs directly then mock up the collectd module, otherwise run it normally - note that this probably doesn’t work as is, you’ll want to use the technique to build a solution that fits your code:

https://gist.github.com/nward/a931f38c5a8b34b8a1cd

I am no python expert, but, this seems to work well enough for my purposes. Apologies if it’s nasty, suggestions for better alternatives are welcome :-)

--
Nathan Ward


More information about the collectd mailing list