@cryptotaxi247 / netdata-1 / commits / 495321346

haproxy plugin: backend status charts added

Ilya committed Jan 12, 2017 at 18:44 UTC 495321346c4a7c52d3e54824fb17ec96eebc66ac
1 file changed +17 -5
python.d/haproxy.chart.py
+17 -5
@@ -10,7 +10,7 @@ priority = 60000
10 retries = 60
11
12 # charts order (can be overridden if you want less charts, or different order)
13 -ORDER = ['fbin', 'fbout', 'fscur', 'fqcur', 'bbin', 'bbout', 'bscur', 'bqcur', 'health_down']
13 +ORDER = ['fbin', 'fbout', 'fscur', 'fqcur', 'bbin', 'bbout', 'bscur', 'bqcur', 'health_sdown', 'health_bdown']
14 CHARTS = {
15 'fbin': {
16 'options': [None, "Kilobytes in", "kilobytes in/s", 'Frontend', 'haproxy_f.bin', 'line'],
@@ -44,8 +44,12 @@ CHARTS = {
44 'options': [None, "Sessions in queue", "sessions", 'Backend', 'haproxy_b.qcur', 'line'],
45 'lines': [
46 ]},
47 - 'health_down': {
48 - 'options': [None, "Servers in DOWN state", "failed servers", 'Health', 'haproxy_h.down', 'line'],
47 + 'health_sdown': {
48 + 'options': [None, "Number of servers in backend in DOWN state", "failed servers", 'Health', 'haproxy_hs.down', 'line'],
49 + 'lines': [
50 + ]},
51 + 'health_bdown': {
52 + 'options': [None, "Is backend alive? 1 = DOWN", "failed backend", 'Health', 'haproxy_hb.down', 'line'],
53 'lines': [
54 ]}
55 }
@@ -93,7 +97,8 @@ class Service(UrlService, SocketService):
97 self.definitions['bbout']['lines'].append(['_'.join(['bbout', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'incremental', 1, 1024])
98 self.definitions['bscur']['lines'].append(['_'.join(['bscur', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'absolute'])
99 self.definitions['bqcur']['lines'].append(['_'.join(['bqcur', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'absolute'])
96 - self.definitions['health_down']['lines'].append(['_'.join(['hdown', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'absolute'])
100 + self.definitions['health_sdown']['lines'].append(['_'.join(['hsdown', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'absolute'])
101 + self.definitions['health_bdown']['lines'].append(['_'.join(['hbdown', back_ends[_]['# pxname']]), back_ends[_]['# pxname'], 'absolute'])
102
103 def _get_data(self):
104 """
@@ -127,8 +132,9 @@ class Service(UrlService, SocketService):
132 to_netdata.update({'_'.join([_, backend['# pxname']]): int(backend[_[1:]]) if backend.get(_[1:]) else 0})
133
134 for _ in range(len(back_ends)):
130 - to_netdata.update({'_'.join(['hdown', back_ends[_]['# pxname']]):
135 + to_netdata.update({'_'.join(['hsdown', back_ends[_]['# pxname']]):
136 len([server for server in servers if is_server_down(server, back_ends, _)])})
137 + to_netdata.update({'_'.join(['hbdown', back_ends[_]['# pxname']]): 1 if is_backend_down(back_ends, _) else 0})
138
139 return to_netdata
140
@@ -163,3 +169,9 @@ def is_server_down(server, back_ends, _):
169 return server['# pxname'] == back_ends[_]['# pxname'] and server['status'] == 'DOWN'
170 except Exception:
171 return False
172 +
173 +def is_backend_down(back_ends, _):
174 + try:
175 + return back_ends[_]['status'] == 'DOWN'
176 + except Exception:
177 + return False