Collect HAproxy backend state per server

Change-Id: I6d7ede0cb9187a3d0ec99a4dfabf96fea0a634b2
This commit is contained in:
Swann Croiset 2016-08-23 13:23:12 +02:00 committed by Simon Pasquier
parent 38ed9a1b82
commit 87ad617638
3 changed files with 17 additions and 0 deletions

View File

@ -240,6 +240,16 @@ class HAProxyPlugin(base.Base):
if pxname not in backend_server_states:
backend_server_states[pxname] = defaultdict(int)
backend_server_states[pxname][stat['status']] += 1
# Emit metric for the backend server
yield {
'type_instance': 'backend_server',
'values': STATUS_MAP[stat['status']],
'meta': {
'backend': pxname,
'state': stat['status'].lower(),
'host': stat['svname'],
}
}
for pxname, states in backend_server_states.iteritems():
for s in STATUS_MAP.keys():

View File

@ -290,6 +290,9 @@ function process_message ()
msg['Fields']['tag_fields'] = { 'frontend' }
msg['Fields']['frontend'] = sample['meta']['frontend']
end
if sample['meta']['host'] then
msg['Fields']['hostname'] = sample['meta']['host']
end
end
elseif metric_source == 'apache' then
metric_name = string.gsub(metric_name, 'apache_', '')

View File

@ -81,6 +81,10 @@ back-end server:
* ``haproxy_backend_servers``, the count of servers grouped by state. This
metric has an additional ``state`` field that contains the state of the
back ends (either 'down' or 'up').
* ``haproxy_backend_server``, the status of the backend server where values
``0`` and ``1`` represent, respectively, ``DOWN`` and ``UP``. This metric
has an additional ``state`` field that contains the state of the backend
(either 'down' or 'up').
* ``haproxy_backend_session_current``, the number of current sessions.
* ``haproxy_backend_session_total``, the cumulative number of sessions.
* ``haproxy_backend_status``, the global back-end status where values ``0``