From d4dd00f58a502c9ca4b63e36ce6bc7a9945dc63c Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Tue, 27 Mar 2018 22:28:21 +0100 Subject: New upstream version 1.10.0+dfsg --- python.d/haproxy.chart.py | 134 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 127 insertions(+), 7 deletions(-) (limited to 'python.d/haproxy.chart.py') diff --git a/python.d/haproxy.chart.py b/python.d/haproxy.chart.py index e72698d10..3061f5ef2 100644 --- a/python.d/haproxy.chart.py +++ b/python.d/haproxy.chart.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Description: haproxy netdata python.d module -# Author: l2isbad +# Author: l2isbad, ktarasz from collections import defaultdict from re import compile as re_compile @@ -20,8 +20,13 @@ priority = 60000 retries = 60 # charts order (can be overridden if you want less charts, or different order) -ORDER = ['fbin', 'fbout', 'fscur', 'fqcur', 'bbin', 'bbout', 'bscur', 'bqcur', - 'health_sdown', 'health_bdown', 'health_idle'] +ORDER = ['fbin', 'fbout', 'fscur', 'fqcur', + 'fhrsp_1xx', 'fhrsp_2xx', 'fhrsp_3xx', 'fhrsp_4xx', 'fhrsp_5xx', 'fhrsp_other', 'fhrsp_total', + 'bbin', 'bbout', 'bscur', 'bqcur', + 'bhrsp_1xx', 'bhrsp_2xx', 'bhrsp_3xx', 'bhrsp_4xx', 'bhrsp_5xx', 'bhrsp_other', 'bhrsp_total', + 'bqtime', 'bttime', 'brtime', 'bctime', + 'health_sup', 'health_sdown', 'health_bdown', 'health_idle'] + CHARTS = { 'fbin': { 'options': [None, "Kilobytes In", "KB/s", 'frontend', 'haproxy_f.bin', 'line'], @@ -39,6 +44,34 @@ CHARTS = { 'options': [None, "Session In Queue", "sessions", 'frontend', 'haproxy_f.qcur', 'line'], 'lines': [ ]}, + 'fhrsp_1xx': { + 'options': [None, "HTTP responses with 1xx code", "responses/s", 'frontend', 'haproxy_f.hrsp_1xx', 'line'], + 'lines': [ + ]}, + 'fhrsp_2xx': { + 'options': [None, "HTTP responses with 2xx code", "responses/s", 'frontend', 'haproxy_f.hrsp_2xx', 'line'], + 'lines': [ + ]}, + 'fhrsp_3xx': { + 'options': [None, "HTTP responses with 3xx code", "responses/s", 'frontend', 'haproxy_f.hrsp_3xx', 'line'], + 'lines': [ + ]}, + 'fhrsp_4xx': { + 'options': [None, "HTTP responses with 4xx code", "responses/s", 'frontend', 'haproxy_f.hrsp_4xx', 'line'], + 'lines': [ + ]}, + 'fhrsp_5xx': { + 'options': [None, "HTTP responses with 5xx code", "responses/s", 'frontend', 'haproxy_f.hrsp_5xx', 'line'], + 'lines': [ + ]}, + 'fhrsp_other': { + 'options': [None, "HTTP responses with other codes (protocol error)", "responses/s", 'frontend', 'haproxy_f.hrsp_other', 'line'], + 'lines': [ + ]}, + 'fhrsp_total': { + 'options': [None, "HTTP responses", "responses", 'frontend', 'haproxy_f.hrsp_total', 'line'], + 'lines': [ + ]}, 'bbin': { 'options': [None, "Kilobytes In", "KB/s", 'backend', 'haproxy_b.bin', 'line'], 'lines': [ @@ -55,11 +88,64 @@ CHARTS = { 'options': [None, "Sessions In Queue", "sessions", 'backend', 'haproxy_b.qcur', 'line'], 'lines': [ ]}, + 'bhrsp_1xx': { + 'options': [None, "HTTP responses with 1xx code", "responses/s", 'backend', 'haproxy_b.hrsp_1xx', 'line'], + 'lines': [ + ]}, + 'bhrsp_2xx': { + 'options': [None, "HTTP responses with 2xx code", "responses/s", 'backend', 'haproxy_b.hrsp_2xx', 'line'], + 'lines': [ + ]}, + 'bhrsp_3xx': { + 'options': [None, "HTTP responses with 3xx code", "responses/s", 'backend', 'haproxy_b.hrsp_3xx', 'line'], + 'lines': [ + ]}, + 'bhrsp_4xx': { + 'options': [None, "HTTP responses with 4xx code", "responses/s", 'backend', 'haproxy_b.hrsp_4xx', 'line'], + 'lines': [ + ]}, + 'bhrsp_5xx': { + 'options': [None, "HTTP responses with 5xx code", "responses/s", 'backend', 'haproxy_b.hrsp_5xx', 'line'], + 'lines': [ + ]}, + 'bhrsp_other': { + 'options': [None, "HTTP responses with other codes (protocol error)", "responses/s", 'backend', + 'haproxy_b.hrsp_other', 'line'], + 'lines': [ + ]}, + 'bhrsp_total': { + 'options': [None, "HTTP responses (total)", "responses/s", 'backend', 'haproxy_b.hrsp_total', 'line'], + 'lines': [ + ]}, + 'bqtime': { + 'options': [None, "The average queue time over the 1024 last requests", "ms", 'backend', 'haproxy_b.qtime', 'line'], + 'lines': [ + ]}, + 'bctime': { + 'options': [None, "The average connect time over the 1024 last requests", "ms", 'backend', + 'haproxy_b.ctime', 'line'], + 'lines': [ + ]}, + 'brtime': { + 'options': [None, "The average response time over the 1024 last requests", "ms", 'backend', + 'haproxy_b.rtime', 'line'], + 'lines': [ + ]}, + 'bttime': { + 'options': [None, "The average total session time over the 1024 last requests", "ms", 'backend', + 'haproxy_b.ttime', 'line'], + 'lines': [ + ]}, 'health_sdown': { 'options': [None, "Backend Servers In DOWN State", "failed servers", 'health', 'haproxy_hs.down', 'line'], 'lines': [ ]}, + 'health_sup': { + 'options': [None, "Backend Servers In UP State", "health servers", 'health', + 'haproxy_hs.up', 'line'], + 'lines': [ + ]}, 'health_bdown': { 'options': [None, "Is Backend Alive? 1 = DOWN", "failed backend", 'health', 'haproxy_hb.down', 'line'], 'lines': [ @@ -71,10 +157,27 @@ CHARTS = { ]} } + METRICS = {'bin': {'algorithm': 'incremental', 'divisor': 1024}, 'bout': {'algorithm': 'incremental', 'divisor': 1024}, 'scur': {'algorithm': 'absolute', 'divisor': 1}, - 'qcur': {'algorithm': 'absolute', 'divisor': 1}} + 'qcur': {'algorithm': 'absolute', 'divisor': 1}, + 'hrsp_1xx': {'algorithm': 'incremental', 'divisor': 1}, + 'hrsp_2xx': {'algorithm': 'incremental', 'divisor': 1}, + 'hrsp_3xx': {'algorithm': 'incremental', 'divisor': 1}, + 'hrsp_4xx': {'algorithm': 'incremental', 'divisor': 1}, + 'hrsp_5xx': {'algorithm': 'incremental', 'divisor': 1}, + 'hrsp_other': {'algorithm': 'incremental', 'divisor': 1}, + } + + +BACKEND_METRICS = { + 'qtime': {'algorithm': 'absolute', 'divisor': 1}, + 'ctime': {'algorithm': 'absolute', 'divisor': 1}, + 'rtime': {'algorithm': 'absolute', 'divisor': 1}, + 'ttime': {'algorithm': 'absolute', 'divisor': 1} +} + REGEX = dict(url=re_compile(r'idle = (?P[0-9]+)'), socket=re_compile(r'Idle_pct: (?P[0-9]+)')) @@ -139,11 +242,19 @@ class Service(UrlService, SocketService): for backend in self.data['backend']: name, idx = backend['# pxname'], backend['# pxname'].replace('.', '_') + stat_data['hsup_' + idx] = len([server for server in self.data['servers'] + if server_status(server, name, 'UP')]) stat_data['hsdown_' + idx] = len([server for server in self.data['servers'] - if server_down(server, name)]) + if server_status(server, name, 'DOWN')]) stat_data['hbdown_' + idx] = 1 if backend.get('status') == 'DOWN' else 0 + for metric in BACKEND_METRICS: + stat_data['_'.join(['backend', metric, idx])] = backend.get(metric) or 0 + hrsp_total = 0 for metric in METRICS: stat_data['_'.join(['backend', metric, idx])] = backend.get(metric) or 0 + if metric.startswith('hrsp_'): + hrsp_total += int(backend.get(metric) or 0) + stat_data['_'.join(['backend', 'hrsp_total', idx])] = hrsp_total return stat_data def _get_info_data(self, regex): @@ -173,12 +284,21 @@ class Service(UrlService, SocketService): self.definitions['f' + metric]['lines'].append(['_'.join(['frontend', metric, idx]), name, METRICS[metric]['algorithm'], 1, METRICS[metric]['divisor']]) + self.definitions['fhrsp_total']['lines'].append(['_'.join(['frontend', 'hrsp_total', idx]), + name, 'incremental', 1, 1]) for back in self.data['backend']: name, idx = back['# pxname'], back['# pxname'].replace('.', '_') for metric in METRICS: self.definitions['b' + metric]['lines'].append(['_'.join(['backend', metric, idx]), name, METRICS[metric]['algorithm'], 1, METRICS[metric]['divisor']]) + self.definitions['bhrsp_total']['lines'].append(['_'.join(['backend', 'hrsp_total', idx]), + name, 'incremental', 1, 1]) + for metric in BACKEND_METRICS: + self.definitions['b' + metric]['lines'].append(['_'.join(['backend', metric, idx]), + name, BACKEND_METRICS[metric]['algorithm'], 1, + BACKEND_METRICS[metric]['divisor']]) + self.definitions['health_sup']['lines'].append(['hsup_' + idx, name, 'absolute']) self.definitions['health_sdown']['lines'].append(['hsdown_' + idx, name, 'absolute']) self.definitions['health_bdown']['lines'].append(['hbdown_' + idx, name, 'absolute']) @@ -210,8 +330,8 @@ def parse_data_(data): return result or None -def server_down(server, backend_name): - return server.get('# pxname') == backend_name and server.get('status') == 'DOWN' +def server_status(server, backend_name, status='DOWN'): + return server.get('# pxname') == backend_name and server.get('status') == status def url_remove_params(url): -- cgit v1.2.3