Netdata Community

How do I add my python plugin?

Problem/Question

I’ve a python script # -*- coding: utf-8 -*-# Description: spigotmc netdata python.d module# Auth - Pastebin.com but i dont know how I can add it into netdata that it loads. I tried adding it into /etc/netdata/python.d.plugin and added into the python.d.conf mcserver: yes but the plugin doesnt load after restart. Did I put it into the correct location and enabled it correctly?
And how can I disable for example the tc.helper?

Hi, @crafter2345 :wave:

Do you mean python plugin or python.d module?

I guess it is python.d module. You need to put your script to the python.d/ dir - /usr/libexec/netdata/python.d/. There you can find all other modules (i installed Netdata to the /opt, so my path is /opt/netdata/usr/libexec/netdata/python.d/):

ilyam@pc ~]$ ls -l /opt/netdata/usr/libexec/netdata/python.d/ | grep chart.py
-rw-r--r-- 1 root root  6697 июл 21 10:47 adaptec_raid.chart.py
-rw-r--r-- 1 root root  3058 июл 21 10:47 alarms.chart.py
-rw-r--r-- 1 root root  1712 июл 21 10:47 am2320.chart.py
-rw-r--r-- 1 root root 21138 июл 21 10:47 anomalies.chart.py
-rw-r--r-- 1 root root  4398 июл 21 10:47 apache.chart.py
-rw-r--r-- 1 root root  8666 июл 21 10:47 beanstalk.chart.py
-rw-r--r-- 1 root root  7964 июл 21 10:47 bind_rndc.chart.py
-rw-r--r-- 1 root root  5438 июл 21 10:47 boinc.chart.py
-rw-r--r-- 1 root root 14837 июл 21 10:47 ceph.chart.py
-rw-r--r-- 1 root root  6636 июл 21 10:47 changefinder.chart.py
-rw-r--r-- 1 root root  3591 июл 21 10:47 chrony.chart.py
-rw-r--r-- 1 root root 15071 июл 21 10:47 couchdb.chart.py
-rw-r--r-- 1 root root  4662 июл 21 10:47 dnsdist.chart.py
...

Hi :wave:
I dropped my mcserver.chart.py in /usr/libexec/netdata/python.d.
In my netdata conf I have
[plugins]
proc = yes
python.d = yes
And in my python.d.conf I have added to the bottom and restarted netdata. But my graph isnt showing up.
mcserver: yes

And my second question was how to disable single modules like tc.helper

Try the debug mode

# as netdata user
/usr/libexec/netdata/plugins.d/python.d.plugin debug 1 mcserver

Disabling tc plugin in the netdata.conf should do

[plugins]
    tc = no

/usr/libexec/netdata/plugins.d/python.d.plugin -ppython3 debug 1 mcserver says

2021-07-21 16:07:04: python.d INFO: plugin[main] : using python v3
2021-07-21 16:07:04: python.d DEBUG: plugin[main] : looking for ‘/etc/netdata/python.d.conf’
2021-07-21 16:07:04: python.d DEBUG: plugin[main] : ‘/etc/netdata/python.d.conf’ is loaded
2021-07-21 16:07:04: python.d DEBUG: plugin[main] : looking for ‘/usr/lib/netdata/conf.d/python.d.conf’
2021-07-21 16:07:04: python.d DEBUG: plugin[main] : ‘/usr/lib/netdata/conf.d/python.d.conf’ is loaded
2021-07-21 16:07:04: python.d DEBUG: plugin[main] : looking for ‘pythond-jobs-statuses.json’ in /var/lib/netdata
2021-07-21 16:07:04: python.d DEBUG: plugin[main] : loading ‘/var/lib/netdata/pythond-jobs-statuses.json’
2021-07-21 16:07:04: python.d DEBUG: plugin[main] : ‘/var/lib/netdata/pythond-jobs-statuses.json’ is loaded
2021-07-21 16:07:04: python.d WARNING: plugin[main] : [mcserver] has no callable Service object, skipping it
2021-07-21 16:07:04: python.d INFO: plugin[main] : no jobs to run

But im logged in as root
My mcserver.chart.py from /usr/libexec/netdata/python.d lookes like # -*- coding: utf-8 -*-# Description: mc netdata python.d moduleimport jso - Pastebin.com
Dont know what I missed

That is the problem. Here you go

import json

from bases.FrameworkServices.UrlService import UrlService

update_every = 10

ORDER = [
    'players',
]

CHARTS = {
    'players': {
        'options': [None, 'Online Minecraft Players', 'players', 'players', 'mcserver.players', 'line'],
        'lines': [
            ['players', 'players', 'absolute', 1, 1]
        ]
    }
}


class Service(UrlService):
    def __init__(self, configuration=None, name=None):
        UrlService.__init__(self, configuration=configuration, name=name)
        self.order = ORDER
        self.definitions = CHARTS
        self.timeout = 5
        self.url = 'https://api.minetools.eu/ping/hypixel.net'

    def _get_data(self):
        raw_data = self._get_raw_data()
        if not raw_data:
            return None

        try:
            response = json.loads(raw_data)
        except ValueError as error:
            self.error('JSON decode error: {}'.format(error))
            return None

        try:
            return {'players': response['players']['online']}
        except KeyError as error:
            self.error('response has no {} key'.format(error))
            return None

@OdysLam this could be a cool community minecraft collector for the new community repos if @crafter2345 was happy to share it - looks like a nice example of fun/interesting stuff from the community.

1 Like

That’s a great idea!

I have outlined my thoughts on how to structure the repo in GitHub issues. I would love to hear some feedback.

For me it woudn’t be a problem. Feel free to use. But there is no config & direct fetch from the minecraft server, for me it is good like it is but probably for others.