From 408f04c3d7067d995b62bcf4b957e904c9c2dff9 Mon Sep 17 00:00:00 2001 From: Andy Walker Date: Fri, 6 Dec 2013 17:00:37 -0600 Subject: [PATCH 1/2] haproxy - Calculate used session percentage Calculate the percentage of used sessions (spct) from the current number of sessions (scur) and the session limit (slim). --- checks.d/haproxy.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/checks.d/haproxy.py b/checks.d/haproxy.py index 8a87e0b5c4..686cb0ce32 100644 --- a/checks.d/haproxy.py +++ b/checks.d/haproxy.py @@ -31,6 +31,7 @@ def __init__(self, name, init_config, agentConfig): "qcur": ("gauge", "queue.current"), "scur": ("gauge", "session.current"), "slim": ("gauge", "session.limit"), + "spct": ("gauge", "session.pct"), # Calculated as: (scur/slim)*100 "stot": ("rate", "session.rate"), "bin": ("rate", "bytes.in_rate"), "bout": ("rate", "bytes.out_rate"), @@ -115,6 +116,13 @@ def _process_data(self, data, collect_aggregates_only, metric_cb=None, event_cb= pass data_dict[fields[i]] = val + # The percentage of used sessions based on 'scur' and 'slim' + if 'slim' in data_dict and 'scur' in data_dict: + try: + data_dict['spct'] = (data_dict['scur'] / data_dict['slim']) * 100 + except TypeError, DivideByZeroError: + pass + # Don't create metrics for aggregates service = data_dict['svname'] if data_dict['svname'] in Services.ALL: From c03b44c2f7456fff6e8ebf5614089ced1e95b7be Mon Sep 17 00:00:00 2001 From: Andy Walker Date: Mon, 9 Dec 2013 14:33:15 -0600 Subject: [PATCH 2/2] haproxy - Catch divide by zero --- checks.d/haproxy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/checks.d/haproxy.py b/checks.d/haproxy.py index 686cb0ce32..313a11e858 100644 --- a/checks.d/haproxy.py +++ b/checks.d/haproxy.py @@ -120,7 +120,7 @@ def _process_data(self, data, collect_aggregates_only, metric_cb=None, event_cb= if 'slim' in data_dict and 'scur' in data_dict: try: data_dict['spct'] = (data_dict['scur'] / data_dict['slim']) * 100 - except TypeError, DivideByZeroError: + except (TypeError, ZeroDivisionError): pass # Don't create metrics for aggregates