add ipfs plugin from paulfantom
davidak committed
Aug 6, 2016 at 16:07 UTC
ae2d41656b1e01fc5263339710060de15357771c
1 file changed
+57
python.d/ipfs.chart.py
new
+57
@@ -0,0 +1,57 @@
1
+# -*- coding: utf-8 -*-
2
+# Description: IPFS netdata python.d module
3
+# Author: Pawel Krupa (paulfantom)
4
+
5
+from base import UrlService
6
+import json
7
+
8
+# default module values (can be overridden per job in `config`)
9
+# update_every = 2
10
+priority = 60000
11
+retries = 60
12
+
13
+# default job configuration (overridden by python.d.plugin)
14
+# config = {'local': {
15
+# 'update_every': update_every,
16
+# 'retries': retries,
17
+# 'priority': priority,
18
+# 'url': 'http://localhost:5001/api/v0/swarm/peers'
19
+# }}
20
+
21
+# charts order (can be overridden if you want less charts, or different order)
22
+ORDER = ['peers']
23
+
24
+CHARTS = {
25
+ 'peers': {
26
+ 'options': [None, 'IPFS Peers', 'peers', 'Peers', 'ipfs.peers', 'line'],
27
+ 'lines': [
28
+ ["peers", None, 'absolute']
29
+ ]}
30
+}
31
+
32
+
33
+class Service(UrlService):
34
+ def __init__(self, configuration=None, name=None):
35
+ UrlService.__init__(self, configuration=configuration, name=name)
36
+ if len(self.url) == 0:
37
+ self.url = "http://localhost:5001/api/v0/swarm/peers"
38
+ self.order = ORDER
39
+ self.definitions = CHARTS
40
+
41
+ def _get_data(self):
42
+ """
43
+ Format data received from http request
44
+ :return: dict
45
+ """
46
+ try:
47
+ raw = self._get_raw_data()
48
+ except AttributeError:
49
+ return None
50
+
51
+ try:
52
+ parsed = json.loads(raw)
53
+ peers = len(parsed['Strings'])
54
+ except:
55
+ return None
56
+
57
+ return {'peers': peers}