Merge pull request #21 from elemoine/stacklight-haproxy
Make haproxy emit backend_servers_percent metrics
diff --git a/collectd/files/plugin/haproxy.py b/collectd/files/plugin/haproxy.py
index 27b5604..2299d6e 100644
--- a/collectd/files/plugin/haproxy.py
+++ b/collectd/files/plugin/haproxy.py
@@ -248,6 +248,7 @@
# NOLB/MAINT/MAINT(via)...
if status in STATUS_MAP:
backend_server_states[pxname][status] += 1
+ backend_server_states[pxname]['_count'] += 1
# Emit metric for the backend server
yield {
'type_instance': 'backend_server',
@@ -261,9 +262,24 @@
for pxname, states in backend_server_states.iteritems():
for s in STATUS_MAP.keys():
+ val = states.get(s, 0)
yield {
'type_instance': 'backend_servers',
- 'values': states.get(s, 0),
+ 'values': val,
+ 'meta': {
+ 'backend': pxname,
+ 'state': s.lower()
+ }
+ }
+
+ if backend_server_states[pxname]['_count'] == 0:
+ prct = 0
+ else:
+ prct = (100.0 * val) / \
+ backend_server_states[pxname]['_count']
+ yield {
+ 'type_instance': 'backend_servers_percent',
+ 'values': prct,
'meta': {
'backend': pxname,
'state': s.lower()