@cryptotaxi247 / netdata-1 / commits / c2eed148f

Improve haproxy monitoring

Added: - hrsp_1xx, hrsp_2xx, hrsp_3xx, hrsp_4xx, hrsp_5xx, hrsp_other, hrsp_total for backands and frontends - qtime, ctime, rtime, ttime metrics for backand servers - Backend Servers In UP State

Taras Kozlovskyi committed Dec 27, 2017 at 16:39 UTC c2eed148f4857f97bb8a35d5f7e2206fc5572eb0
1 file changed +128 -7
python.d/haproxy.chart.py
+128 -7
@@ -1,6 +1,6 @@
1 # -*- coding: utf-8 -*-
2 # Description: haproxy netdata python.d module
3 -# Author: l2isbad
3 +# Author: l2isbad, ktarasz
4
5 from collections import defaultdict
6 from re import compile as re_compile
@@ -20,8 +20,13 @@ priority = 60000
20 retries = 60
21
22 # charts order (can be overridden if you want less charts, or different order)
23 -ORDER = ['fbin', 'fbout', 'fscur', 'fqcur', 'bbin', 'bbout', 'bscur', 'bqcur',
24 - 'health_sdown', 'health_bdown', 'health_idle']
23 +ORDER = ['fbin', 'fbout', 'fscur', 'fqcur',
24 + 'fhrsp_1xx', 'fhrsp_2xx', 'fhrsp_3xx', 'fhrsp_4xx', 'fhrsp_5xx', 'fhrsp_other', 'fhrsp_total',
25 + 'bbin', 'bbout', 'bscur', 'bqcur',
26 + 'bhrsp_1xx', 'bhrsp_2xx', 'bhrsp_3xx', 'bhrsp_4xx', 'bhrsp_5xx', 'bhrsp_other', 'bhrsp_total',
27 + 'bqtime', 'bttime', 'brtime', 'bctime',
28 + 'health_sup', 'health_sdown', 'health_bdown', 'health_idle']
29 +
30 CHARTS = {
31 'fbin': {
32 'options': [None, "Kilobytes In", "KB/s", 'frontend', 'haproxy_f.bin', 'line'],
@@ -39,6 +44,34 @@ CHARTS = {
44 'options': [None, "Session In Queue", "sessions", 'frontend', 'haproxy_f.qcur', 'line'],
45 'lines': [
46 ]},
47 + 'fhrsp_1xx': {
48 + 'options': [None, "HTTP responses with 1xx code", "responses", 'frontend', 'haproxy_f.hrsp_1xx', 'line'],
49 + 'lines': [
50 + ]},
51 + 'fhrsp_2xx': {
52 + 'options': [None, "HTTP responses with 2xx code", "responses", 'frontend', 'haproxy_f.hrsp_2xx', 'line'],
53 + 'lines': [
54 + ]},
55 + 'fhrsp_3xx': {
56 + 'options': [None, "HTTP responses with 3xx code", "responses", 'frontend', 'haproxy_f.hrsp_3xx', 'line'],
57 + 'lines': [
58 + ]},
59 + 'fhrsp_4xx': {
60 + 'options': [None, "HTTP responses with 4xx code", "responses", 'frontend', 'haproxy_f.hrsp_4xx', 'line'],
61 + 'lines': [
62 + ]},
63 + 'fhrsp_5xx': {
64 + 'options': [None, "HTTP responses with 5xx code", "responses", 'frontend', 'haproxy_f.hrsp_5xx', 'line'],
65 + 'lines': [
66 + ]},
67 + 'fhrsp_other': {
68 + 'options': [None, "HTTP responses with other codes (protocol error)", "responses", 'frontend', 'haproxy_f.hrsp_other', 'line'],
69 + 'lines': [
70 + ]},
71 + 'fhrsp_total': {
72 + 'options': [None, "HTTP responses", "responses", 'frontend', 'haproxy_f.hrsp_total', 'line'],
73 + 'lines': [
74 + ]},
75 'bbin': {
76 'options': [None, "Kilobytes In", "KB/s", 'backend', 'haproxy_b.bin', 'line'],
77 'lines': [
@@ -55,11 +88,64 @@ CHARTS = {
88 'options': [None, "Sessions In Queue", "sessions", 'backend', 'haproxy_b.qcur', 'line'],
89 'lines': [
90 ]},
91 + 'bhrsp_1xx': {
92 + 'options': [None, "HTTP responses with 1xx code", "responses", 'backend', 'haproxy_b.hrsp_1xx', 'line'],
93 + 'lines': [
94 + ]},
95 + 'bhrsp_2xx': {
96 + 'options': [None, "HTTP responses with 2xx code", "responses", 'backend', 'haproxy_b.hrsp_2xx', 'line'],
97 + 'lines': [
98 + ]},
99 + 'bhrsp_3xx': {
100 + 'options': [None, "HTTP responses with 3xx code", "responses", 'backend', 'haproxy_b.hrsp_3xx', 'line'],
101 + 'lines': [
102 + ]},
103 + 'bhrsp_4xx': {
104 + 'options': [None, "HTTP responses with 4xx code", "responses", 'backend', 'haproxy_b.hrsp_4xx', 'line'],
105 + 'lines': [
106 + ]},
107 + 'bhrsp_5xx': {
108 + 'options': [None, "HTTP responses with 5xx code", "responses", 'backend', 'haproxy_b.hrsp_5xx', 'line'],
109 + 'lines': [
110 + ]},
111 + 'bhrsp_other': {
112 + 'options': [None, "HTTP responses with other codes (protocol error)", "responses", 'backend',
113 + 'haproxy_b.hrsp_other', 'line'],
114 + 'lines': [
115 + ]},
116 + 'bhrsp_total': {
117 + 'options': [None, "HTTP responses (total)", "responses", 'backend', 'haproxy_b.hrsp_total', 'line'],
118 + 'lines': [
119 + ]},
120 + 'bqtime': {
121 + 'options': [None, "The average queue time over the 1024 last requests", "ms", 'backend', 'haproxy_b.qtime', 'line'],
122 + 'lines': [
123 + ]},
124 + 'bctime': {
125 + 'options': [None, "The average connect time over the 1024 last requests", "ms", 'backend',
126 + 'haproxy_b.ctime', 'line'],
127 + 'lines': [
128 + ]},
129 + 'brtime': {
130 + 'options': [None, "The average response time over the 1024 last requests", "ms", 'backend',
131 + 'haproxy_b.rtime', 'line'],
132 + 'lines': [
133 + ]},
134 + 'bttime': {
135 + 'options': [None, "The average total session time over the 1024 last requests", "ms", 'backend',
136 + 'haproxy_b.ttime', 'line'],
137 + 'lines': [
138 + ]},
139 'health_sdown': {
140 'options': [None, "Backend Servers In DOWN State", "failed servers", 'health',
141 'haproxy_hs.down', 'line'],
142 'lines': [
143 ]},
144 + 'health_sup': {
145 + 'options': [None, "Backend Servers In UP State", "health servers", 'health',
146 + 'haproxy_hs.up', 'line'],
147 + 'lines': [
148 + ]},
149 'health_bdown': {
150 'options': [None, "Is Backend Alive? 1 = DOWN", "failed backend", 'health', 'haproxy_hb.down', 'line'],
151 'lines': [
@@ -71,10 +157,27 @@ CHARTS = {
157 ]}
158 }
159
160 +
161 METRICS = {'bin': {'algorithm': 'incremental', 'divisor': 1024},
162 'bout': {'algorithm': 'incremental', 'divisor': 1024},
163 'scur': {'algorithm': 'absolute', 'divisor': 1},
77 - 'qcur': {'algorithm': 'absolute', 'divisor': 1}}
164 + 'qcur': {'algorithm': 'absolute', 'divisor': 1},
165 + 'hrsp_1xx': {'algorithm': 'incremental', 'divisor': 1},
166 + 'hrsp_2xx': {'algorithm': 'incremental', 'divisor': 1},
167 + 'hrsp_3xx': {'algorithm': 'incremental', 'divisor': 1},
168 + 'hrsp_4xx': {'algorithm': 'incremental', 'divisor': 1},
169 + 'hrsp_5xx': {'algorithm': 'incremental', 'divisor': 1},
170 + 'hrsp_other': {'algorithm': 'incremental', 'divisor': 1},
171 + }
172 +
173 +
174 +BACKEND_METRICS = {
175 + 'qtime': {'algorithm': 'absolute', 'divisor': 1},
176 + 'ctime': {'algorithm': 'absolute', 'divisor': 1},
177 + 'rtime': {'algorithm': 'absolute', 'divisor': 1},
178 + 'ttime': {'algorithm': 'absolute', 'divisor': 1}
179 +}
180 +
181
182 REGEX = dict(url=re_compile(r'idle = (?P<idle>[0-9]+)'),
183 socket=re_compile(r'Idle_pct: (?P<idle>[0-9]+)'))
@@ -139,11 +242,20 @@ class Service(UrlService, SocketService):
242
243 for backend in self.data['backend']:
244 name, idx = backend['# pxname'], backend['# pxname'].replace('.', '_')
245 + stat_data['hsup_' + idx] = len([server for server in self.data['servers']
246 + if server_status(server, name, 'UP')])
247 stat_data['hsdown_' + idx] = len([server for server in self.data['servers']
143 - if server_down(server, name)])
248 + if server_status(server, name, 'DOWN')])
249 stat_data['hbdown_' + idx] = 1 if backend.get('status') == 'DOWN' else 0
250 + for metric in BACKEND_METRICS:
251 + stat_data['_'.join(['backend', metric, idx])] = backend.get(metric) or 0
252 + hrsp_total = 0
253 for metric in METRICS:
254 stat_data['_'.join(['backend', metric, idx])] = backend.get(metric) or 0
255 + if metric.startswith('hrsp_'):
256 + hrsp_total += int(backend.get(metric) or 0)
257 + if hrsp_total:
258 + stat_data['_'.join(['backend', 'hrsp_total', idx])] = hrsp_total
259 return stat_data
260
261 def _get_info_data(self, regex):
@@ -173,12 +285,21 @@ class Service(UrlService, SocketService):
285 self.definitions['f' + metric]['lines'].append(['_'.join(['frontend', metric, idx]),
286 name, METRICS[metric]['algorithm'], 1,
287 METRICS[metric]['divisor']])
288 + self.definitions['fhrsp_total']['lines'].append(['_'.join(['frontend', 'hrsp_total', idx]),
289 + name, 'incremental', 1, 1])
290 for back in self.data['backend']:
291 name, idx = back['# pxname'], back['# pxname'].replace('.', '_')
292 for metric in METRICS:
293 self.definitions['b' + metric]['lines'].append(['_'.join(['backend', metric, idx]),
294 name, METRICS[metric]['algorithm'], 1,
295 METRICS[metric]['divisor']])
296 + self.definitions['bhrsp_total']['lines'].append(['_'.join(['backend', 'hrsp_total', idx]),
297 + name, 'incremental', 1, 1])
298 + for metric in BACKEND_METRICS:
299 + self.definitions['b' + metric]['lines'].append(['_'.join(['backend', metric, idx]),
300 + name, BACKEND_METRICS[metric]['algorithm'], 1,
301 + BACKEND_METRICS[metric]['divisor']])
302 + self.definitions['health_sup']['lines'].append(['hsup_' + idx, name, 'absolute'])
303 self.definitions['health_sdown']['lines'].append(['hsdown_' + idx, name, 'absolute'])
304 self.definitions['health_bdown']['lines'].append(['hbdown_' + idx, name, 'absolute'])
305
@@ -210,8 +331,8 @@ def parse_data_(data):
331 return result or None
332
333
213 -def server_down(server, backend_name):
214 - return server.get('# pxname') == backend_name and server.get('status') == 'DOWN'
334 +def server_status(server, backend_name, status='DOWN'):
335 + return server.get('# pxname') == backend_name and server.get('status') == status
336
337
338 def url_remove_params(url):