]> arthur.barton.de Git - netdata.git/commitdiff
add RetroShare
authorsehraf <sehraf@privatdemail.net>
Tue, 6 Sep 2016 15:57:59 +0000 (17:57 +0200)
committersehraf <sehraf@privatdemail.net>
Wed, 7 Sep 2016 11:48:34 +0000 (13:48 +0200)
conf.d/Makefile.am
conf.d/python.d/retroshare.conf [new file with mode: 0644]
python.d/Makefile.am
python.d/retroshare.chart.py [new file with mode: 0644]

index 4dff03877513528cae435d1f55aff35a7c7a1521..46a79e9f40c35f8ee29defa5bddbb6c1c690785c 100644 (file)
@@ -35,6 +35,7 @@ dist_pythonconfig_DATA = \
        python.d/phpfpm.conf \
        python.d/postfix.conf \
        python.d/redis.conf \
+       python.d/retroshare.conf \
        python.d/sensors.conf \
        python.d/squid.conf \
        python.d/tomcat.conf \
diff --git a/conf.d/python.d/retroshare.conf b/conf.d/python.d/retroshare.conf
new file mode 100644 (file)
index 0000000..7e974c8
--- /dev/null
@@ -0,0 +1,66 @@
+# netdata python.d.plugin configuration for example
+#
+# This file is in YaML format. Generally the format is:
+#
+# name: value
+#
+# There are 2 sections:
+#  - global variables
+#  - one or more JOBS
+#
+# JOBS allow you to collect values from multiple sources.
+# Each source will have its own set of charts.
+#
+# JOB parameters have to be indented (using spaces only, example below).
+
+# ----------------------------------------------------------------------
+# Global Variables
+# These variables set the defaults for all JOBs, however each JOB
+# may define its own, overriding the defaults.
+
+# update_every sets the default data collection frequency.
+# If unset, the python.d.plugin default is used.
+# update_every: 1
+
+# priority controls the order of charts at the netdata dashboard.
+# Lower numbers move the charts towards the top of the page.
+# If unset, the default for python.d.plugin is used.
+# priority: 60000
+
+# retries sets the number of retries to be made in case of failures.
+# If unset, the default for python.d.plugin is used.
+# Attempts to restore the service are made once every update_every
+# and only if the module has collected values in the past.
+# retries: 5
+
+# ----------------------------------------------------------------------
+# JOBS (data collection sources)
+#
+# The default JOBS share the same *name*. JOBS with the same name
+# are mutually exclusive. Only one of them will be allowed running at
+# any time. This allows autodetection to try several alternatives and
+# pick the one that works.
+#
+# Any number of jobs is supported.
+#
+# All python.d.plugin JOBS (for all its modules) support a set of
+# predefined parameters. These are:
+#
+# job_name:
+#     name: myname     # the JOB's name as it will appear at the
+#                      # dashboard (by default is the job_name)
+#                      # JOBs sharing a name are mutually exclusive
+#     update_every: 1  # the JOB's data collection frequency
+#     priority: 60000  # the JOB's order on the dashboard
+#     retries: 5       # the JOB's number of restoration attempts
+#
+# Additionally to the above, example also supports the following:
+#
+# - none
+#
+# ----------------------------------------------------------------------
+# AUTO-DETECTION JOBS
+# only one of them will run (they have the same name)
+
+local:
+    url: 'http://localhost:9090'
index 8bccba3780d706fce07c682c030b311ff484dd72..d769e313868cea76f22d0c8a00ce463184e81722 100644 (file)
@@ -23,6 +23,7 @@ dist_python_SCRIPTS = \
        phpfpm.chart.py \
        postfix.chart.py \
        redis.chart.py \
+       retroshare.chart.py \
        sensors.chart.py \
        squid.chart.py \
        tomcat.chart.py \
diff --git a/python.d/retroshare.chart.py b/python.d/retroshare.chart.py
new file mode 100644 (file)
index 0000000..0c97973
--- /dev/null
@@ -0,0 +1,78 @@
+# -*- coding: utf-8 -*-
+# Description: RetroShare netdata python.d module
+# Authors: sehraf
+
+from base import UrlService
+import json
+
+# default module values (can be overridden per job in `config`)
+# update_every = 2
+priority = 60000
+retries = 60
+
+# charts order (can be overridden if you want less charts, or different order)
+ORDER = ['bandwidth', 'peers', 'dht']
+
+CHARTS = {
+    'bandwidth': {
+        'options': [None, 'RetroShare Bandwidth', 'kB/s', 'RetroShare', 'retroshare.bandwidth', 'area'],
+        'lines': [
+            ['bandwidth_up_kb',   'Upload'],
+            ['bandwidth_down_kb', 'Download']
+        ]},
+    'peers': {
+        'options': [None, 'RetroShare Peers', 'peers', 'RetroShare', 'retroshare.peers', 'line'],
+        'lines': [
+            ['peers_all',       'All friends'],
+            ['peers_connected', 'Connected friends']
+        ]},
+    'dht': {
+        'options': [None, 'Retroshare DHT', 'peers', 'RetroShare', 'retroshare.dht', 'line'],
+        'lines': [
+            ['dht_size_all', 'DHT nodes estimated'],
+            ['dht_size_rs',  'RS nodes estimated']
+        ]}
+}
+
+
+class Service(UrlService):
+    def __init__(self, configuration=None, name=None):
+        UrlService.__init__(self, configuration=configuration, name=name)
+        try:
+            self.baseurl = str(self.configuration['url'])
+        except (KeyError, TypeError):
+            self.baseurl = 'http://localhost:9090'
+        self.order = ORDER
+        self.definitions = CHARTS
+
+    def _get_stats(self):
+        """
+        Format data received from http request
+        :return: dict
+        """
+        try:
+            raw = self._get_raw_data()
+            parsed = json.loads(raw)
+            if str(parsed['returncode']) != 'ok':
+                return None
+        except:
+            return None
+
+        return parsed['data'][0]
+
+    def _get_data(self):
+        """
+        Get data from API
+        :return: dict
+        """
+        self.url = self.baseurl + '/api/v2/stats'
+        data = self._get_stats()
+        if data is None:
+            return None
+
+        data['bandwidth_up_kb'] = data['bandwidth_up_kb'] * -1
+        if data['dht_active'] is False:
+            data['dht_size_all'] = None
+            data['dht_size_rs'] = None
+
+        return data