1 # -*- coding: utf-8 -*-
2 # Description: IPFS netdata python.d module
3 # Authors: Pawel Krupa (paulfantom), davidak
5 from base import UrlService
8 # default module values (can be overridden per job in `config`)
13 # default job configuration (overridden by python.d.plugin)
14 # config = {'local': {
15 # 'update_every': update_every,
17 # 'priority': priority,
18 # 'url': 'http://localhost:5001'
21 # charts order (can be overridden if you want less charts, or different order)
22 ORDER = ['bandwidth', 'peers', 'repo_size', 'repo_objects']
26 'options': [None, 'IPFS Bandwidth', 'kbits/s', 'Bandwidth', 'ipfs.bandwidth', 'line'],
28 ["in", None, "absolute", 8, 1000],
29 ["out", None, "absolute", -8, 1000]
32 'options': [None, 'IPFS Peers', 'peers', 'Peers', 'ipfs.peers', 'line'],
34 ["peers", None, 'absolute']
37 'options': [None, 'IPFS Repo Size', 'MB', 'Size', 'ipfs.repo_size', 'line'],
39 ["size", None, "absolute", 1, 1000000]
42 'options': [None, 'IPFS Repo Objects', 'objects', 'Objects', 'ipfs.repo_objects', 'line'],
44 ["objects", None, "absolute", 1, 1],
45 ["pinned", None, "absolute", 1, 1],
46 ["recursive_pins", None, "absolute", 1, 1]
50 class Service(UrlService):
51 def __init__(self, configuration=None, name=None):
52 UrlService.__init__(self, configuration=configuration, name=name)
54 self.baseurl = str(self.configuration['url'])
55 except (KeyError, TypeError):
56 self.baseurl = "http://localhost:5001"
58 self.definitions = CHARTS
60 def _get_json(self, suburl):
62 :return: json decoding of the specified url
64 self.url = self.baseurl + suburl
66 return json.loads(self._get_raw_data())
70 def _recursive_pins(self, keys):
71 return len([k for k in keys if keys[k]["Type"] == b"recursive"])
79 cfg = {# suburl : List of (result-key, original-key, transform-func)
80 '/api/v0/stats/bw' :[('in', 'RateIn', int ),
81 ('out', 'RateOut', int )],
82 '/api/v0/swarm/peers':[('peers', 'Strings', len )],
83 '/api/v0/stats/repo' :[('size', 'RepoSize', int),
84 ('objects', 'NumObjects', int)],
85 '/api/v0/pin/ls': [('pinned', 'Keys', len),
86 ('recursive_pins', 'Keys', self._recursive_pins)
91 json = self._get_json(suburl)
92 for newkey, origkey, xmute in cfg[suburl]:
94 r[newkey] = xmute(json[origkey])