[collectd] problem with importing collectd python module

Nils Steinger nrg_collectd at voidptr.de
Sun Feb 7 19:23:52 CET 2016


Hi Pawel,

your configuration stanza isn't entirely correct:
The "ModulePath" options needs to point to a directory, from which
collectd will try to load the corresponding module for each "Import"
line.
In your case
>         ModulePath "/var/lib/collectd/mongodb.py"
should probably be
>         ModulePath "/var/lib/collectd/"
as collectd will append "mongodb.py" automatically when it parses
>         Import "mongodb"

That way, you could also load multiple Python modules from the same path
by using multiple "Import" lines in the configuration.

Regards,
Nils

On 07.02.2016 14:05, Pawel Akonom wrote:
> Hi Nils,
> 
> Yes I am loading the plugin from collectd config file. Here is the python plugin part of my /etc/collectd.conf file:
> 
> LoadPlugin python
> <Plugin python>
>         ModulePath "/var/lib/collectd/mongodb.py"
>         Import "mongodb"
>         <Module mongodb>
>                 Host "127.0.0.1"
>                 Database "virtunomic"
>         </Module>
> </Plugin>
> 
> mongodb.py file is the one from https://github.com/sebest/collectd-mongodb/blob/master/mongodb.py
> 
> collectd can't load the plugin and when I run python script manually - just as a python script I got error: can't load collectd module. The error is in line 5 of the python script "import collectd". In collectd log file there is different error so maybe it could load collectd module when is run from collectd daemon. The error in log file is: ImportError: No module named mongodb
> 
> [root at cisco_aci_dev184 ~]# /etc/init.d/collectd restart ; tail -f /var/log/collectd.log 
> Stopping collectd:                                         [  OK  ]
> Starting collectd:                                         [  OK  ]
> [2016-02-07 04:50:13] python plugin: Error importing module "mongodb".
> [2016-02-07 04:50:13] Unhandled python exception in importing module: ImportError: No module named mongodb
> [2016-02-07 04:50:13] python plugin: Found a configuration for the "mongodb" plugin, but the plugin isn't loaded or didn't register a configuration callback.
> [2016-02-07 04:50:13] logfile: invalid loglevel [debug] defaulting to 'info'
> [2016-02-07 04:50:14] python plugin: Error importing module "mongodb".
> [2016-02-07 04:50:14] Unhandled python exception in importing module: ImportError: No module named mongodb
> [2016-02-07 04:50:14] python plugin: Found a configuration for the "mongodb" plugin, but the plugin isn't loaded or didn't register a configuration callback.
> [2016-02-07 04:50:14] logfile: invalid loglevel [debug] defaulting to 'info'
> [2016-02-07 04:50:14] python plugin: Error importing module "mongodb".
> [2016-02-07 04:50:14] Unhandled python exception in importing module: ImportError: No module named mongodb
> [2016-02-07 04:50:14] python plugin: Found a configuration for the "mongodb" plugin, but the plugin isn't loaded or didn't register a configuration callback.
> [2016-02-07 04:50:14] Initialization complete, entering read-loop.
> ^C
> [root at cisco_aci_dev184 ~]# ls -la /var/lib/collectd/mongodb.py
> -rwxr-xr-x. 1 root root 5408 Feb  5 08:48 /var/lib/collectd/mongodb.py
> [root at cisco_aci_dev184 ~]# python /var/lib/collectd/mongodb.py
> Traceback (most recent call last):
>   File "/var/lib/collectd/mongodb.py", line 5, in <module>
>     import collectd
> ImportError: No module named collectd
> 
> Thanks in advance for any hints about the problem.
> 
> Best Regards,
> Pawel
> 
> From: Nils Steinger <nrg_collectd at voidptr.de>
> Sent: Saturday, February 6, 2016 5:13 PM
> To: Pawel Akonom; collectd at verplant.org
> Subject: Re: [collectd] problem with importing collectd python module
> 
> Hi Pawel,
> 
> are you loading the plugin from collectd's config file as described in
> its documentation [1]?
> Python scripts importing the collectd module are meant to be run by a
> Python interpreter included in collectd (by loading and configuring the
> "Python" plugin in collectd.conf) to avoid the overhead of running
> multiple Python interpreters. Running those scripts manually from the
> commandline won't work.
> To add to the confusion, there's also a Python wrapper around collectd's
> Unix socket interface, but that one isn't used here.
> 
> Regards,
> Nils
> 
> [1]: https://github.com/sebest/collectd-mongodb#configuration
> 
> On 06.02.2016 14:54, Pawel Akonom 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.
>>
>> Br,
>> Pawel
>> ________________________________________
>> From: Joshua J. Kugler <joshua at azariah.com>
>> Sent: Saturday, February 6, 2016 1:13 AM
>> To: collectd at verplant.org
>> Cc: Pawel Akonom; Derek Palma
>> Subject: Re: [collectd] problem with importing collectd python module
>>
>> On Friday, February 05, 2016 19:39:50 Pawel Akonom wrote:
>>> The first line of mongodb.py plugin is:
>>>
>>>
>>> "import collectd" and the plugin can't load it. When I run python shell and
>>> try to import collectd manually I get:
>>>
>>>
>>> [root at cisco_aci_dev184 ~]# python
>>> Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18)
>>> [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
>>> Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>>>> import collectd
>>>
>>> Traceback (most recent call last):
>>>   File "<stdin>", line 1, in <module>
>>> ImportError: No module named collectd
>>
>> Can you clarify what you mean by "the plugin can't load it?" Do you can an
>> error? Or is the Python plugin not finding the mongodb.py plugin?
>>
>> Per the wiki page here: https://collectd.org/wiki/index.php/Plugin:Python you
>> will need to provide a path to the module you're trying load.  Can you post
>> your collectd config?
>>
>> j
>>
>> --
>> Joshua J. Kugler - Fairbanks, Alaska
>> Azariah Enterprises - Programming and Website Design
>> joshua at azariah.com - Jabber: pedahzur at gmail.com
>> PGP Key: http://pgp.mit.edu/  ID 0x73B13B6A
>>
>> _______________________________________________
>> collectd mailing list
>> collectd at verplant.org
>> http://mailman.verplant.org/listinfo/collectd
>>
> 
> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.verplant.org/pipermail/collectd/attachments/20160207/809488ef/attachment.sig>


More information about the collectd mailing list