Add health tracking for ipfs
Paul Jimenez committed
Jan 12, 2017 at 10:27 UTC
885c83488d2e55826cd07f8fabe7c95bbee6d1e2
2 files changed
+43
-9
conf.d/health.d/ipfs.conf
new
+11
@@ -0,0 +1,11 @@
1
+
2
+ alarm: ipfs_datastore_in_use
3
+ on: ipfs_local.repo_size
4
+ calc: $size * 100 / $avail
5
+ units: %
6
+ every: 10s
7
+ warn: $this > (($status >= $WARNING) ? (80) : (90))
8
+ crit: $this > (($status == $CRITICAL) ? (90) : (98))
9
+ delay: down 15m multiplier 1.5 max 1h
10
+ info: ipfs Datastore close to running out of space
11
+ to: sysadmin
python.d/ipfs.chart.py
+32
-9
@@ -34,9 +34,10 @@ CHARTS = {
34
["peers", None, 'absolute']
35
]},
36
'repo_size': {
37
- 'options': [None, 'IPFS Repo Size', 'MB', 'Size', 'ipfs.repo_size', 'line'],
37
+ 'options': [None, 'IPFS Repo Size', 'GB', 'Size', 'ipfs.repo_size', 'area'],
38
'lines': [
39
- ["size", None, "absolute", 1, 1000000]
39
+ ["avail", None, "absolute", 1, 1e9],
40
+ ["size", None, "absolute", 1, 1e9],
41
]},
42
'repo_objects': {
43
'options': [None, 'IPFS Repo Objects', 'objects', 'Objects', 'ipfs.repo_objects', 'line'],
@@ -47,6 +48,10 @@ CHARTS = {
48
]},
49
}
50
51
+SI_zeroes = {'k': 3, 'm': 6, 'g': 9, 't': 12,
52
+ 'p': 15, 'e': 18, 'z': 21, 'y': 24 }
53
+
54
+
55
class Service(UrlService):
56
def __init__(self, configuration=None, name=None):
57
UrlService.__init__(self, configuration=configuration, name=name)
@@ -56,35 +61,55 @@ class Service(UrlService):
61
self.baseurl = "http://localhost:5001"
62
self.order = ORDER
63
self.definitions = CHARTS
64
+ self.__storagemax = None
65
66
def _get_json(self, suburl):
67
"""
68
:return: json decoding of the specified url
63
- """
69
+ """
70
self.url = self.baseurl + suburl
71
try:
66
- return json.loads(self._get_raw_data())
72
+ return json.loads(self._get_raw_data())
73
except:
74
return {}
75
76
def _recursive_pins(self, keys):
77
return len([k for k in keys if keys[k]["Type"] == b"recursive"])
78
79
+ def _dehumanize(self, storemax):
80
+ # convert from '10Gb' to 10000000000
81
+ if type(storemax) != int:
82
+ storemax = storemax.lower()
83
+ if storemax.endswith('b'):
84
+ val, units = storemax[:-2], storemax[-2]
85
+ if units in SI_zeroes:
86
+ val += '0'*SI_zeroes[units]
87
+ storemax = val
88
+ try:
89
+ storemax = int(storemax)
90
+ except:
91
+ storemax = None
92
+ return storemax
93
+
94
+ def _storagemax(self, storecfg):
95
+ if self.__storagemax is None:
96
+ self.__storagemax = self._dehumanize(storecfg['StorageMax'])
97
+ return self.__storagemax
98
99
def _get_data(self):
100
"""
101
Get data from API
102
:return: dict
103
"""
79
- cfg = {# suburl : List of (result-key, original-key, transform-func)
104
+ cfg = { # suburl : List of (result-key, original-key, transform-func)
105
'/api/v0/stats/bw' :[('in', 'RateIn', int ),
106
('out', 'RateOut', int )],
107
'/api/v0/swarm/peers':[('peers', 'Strings', len )],
108
'/api/v0/stats/repo' :[('size', 'RepoSize', int),
109
('objects', 'NumObjects', int)],
110
'/api/v0/pin/ls': [('pinned', 'Keys', len),
86
- ('recursive_pins', 'Keys', self._recursive_pins)
87
- ]
111
+ ('recursive_pins', 'Keys', self._recursive_pins)],
112
+ '/api/v0/config/show': [('avail', 'Datastore', self._storagemax)]
113
}
114
r = {}
115
for suburl in cfg:
@@ -96,5 +121,3 @@ class Service(UrlService):
121
return r or None
122
123
99
-
100
-