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']
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']
39 class Service(UrlService):
40 def __init__(self, configuration=None, name=None):
41 UrlService.__init__(self, configuration=configuration, name=name)
42 if len(self.url) == 0:
43 self.baseurl = "http://localhost:5001/"
45 self.baseurl = self.url
47 self.definitions = CHARTS
49 def _get_bandwidth(self):
51 Format data received from http request
54 self.url = self.baseurl + "api/v0/stats/bw"
56 raw = self._get_raw_data()
57 except AttributeError:
61 parsed = json.loads(raw)
62 bw_in = int(parsed['RateIn'])
63 bw_out = int(parsed['RateOut'])
71 Format data received from http request
74 self.url = self.baseurl + "api/v0/swarm/peers"
76 raw = self._get_raw_data()
77 except AttributeError:
81 parsed = json.loads(raw)
82 peers = len(parsed['Strings'])
93 peers = self._get_peers()
94 bandwidth_in, bandwidth_out = self._get_bandwidth()
96 return {'peers': peers, 'in': bandwidth_in, 'out': bandwidth_out}