@cryptotaxi247 / netdata-1 / commits / cff07d432

ipfs: fix configuration

davidak committed Aug 7, 2016 at 19:19 UTC cff07d4322e748c57cf926241d9eb2828ba64b76
2 files changed +22 -11
conf.d/python.d/ipfs.conf
+1 -1
@@ -64,4 +64,4 @@
64
65 localhost:
66 name : 'local'
67 - url : 'http://localhost:5001/'
67 + url : 'http://localhost:5001'
python.d/ipfs.chart.py
+21 -10
@@ -15,7 +15,7 @@ retries = 60
15 # 'update_every': update_every,
16 # 'retries': retries,
17 # 'priority': priority,
18 -# 'url': 'http://localhost:5001/'
18 +# 'url': 'http://localhost:5001'
19 # }}
20
21 # charts order (can be overridden if you want less charts, or different order)
@@ -39,10 +39,10 @@ CHARTS = {
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/"
44 - else:
45 - self.baseurl = self.url
42 + try:
43 + self.baseurl = str(self.configuration['url'])
44 + except (KeyError, TypeError):
45 + self.baseurl = "http://localhost:5001"
46 self.order = ORDER
47 self.definitions = CHARTS
48
@@ -51,7 +51,7 @@ class Service(UrlService):
51 Format data received from http request
52 :return: int, int
53 """
54 - self.url = self.baseurl + "api/v0/stats/bw"
54 + self.url = self.baseurl + "/api/v0/stats/bw"
55 try:
56 raw = self._get_raw_data()
57 except AttributeError:
@@ -71,7 +71,7 @@ class Service(UrlService):
71 Format data received from http request
72 :return: int
73 """
74 - self.url = self.baseurl + "api/v0/swarm/peers"
74 + self.url = self.baseurl + "/api/v0/swarm/peers"
75 try:
76 raw = self._get_raw_data()
77 except AttributeError:
@@ -90,7 +90,18 @@ class Service(UrlService):
90 Get data from API
91 :return: dict
92 """
93 - peers = self._get_peers()
94 - bandwidth_in, bandwidth_out = self._get_bandwidth()
93 + try:
94 + peers = self._get_peers()
95 + bandwidth_in, bandwidth_out = self._get_bandwidth()
96 + except:
97 + return None
98 + data = {}
99 + if peers is not None:
100 + data['peers'] = peers
101 + if bandwidth_in is not None and bandwidth_out is not None:
102 + data['in'] = bandwidth_in
103 + data['out'] = bandwidth_out
104
96 - return {'peers': peers, 'in': bandwidth_in, 'out': bandwidth_out}
105 + if len(data) == 0:
106 + return None
107 + return data