collectd_haproxy.connection

class collectd_haproxy.connection.HAProxySocket(collectd, socket_file_path)[source]

Bases: object

Class used for interacting with an HAProxy control socket.

Provides two methods for generating metrics, one for the “info” metrics that give process-wide details and the “stats” metrics for individual proxies/servers.

The HAProxySocket constructor.

Since the collectd module is only available when the plugin is running in collectd’s python process we use some dependency injection here.

Parameters:
  • collectd (module) – The collectd module.
  • socket_file_path (str) – Full path to HAProxy’s socket file.
send_command(command)[source]

Sends a given command to the HAProxy socket.

Collects the response (it can arrive in chunks) and then calls the process_command_response method on the result.

Parameters:command (str) – The command to send, e.g. “show stat”
process_command_response(command, response)[source]

Takes an HAProxy socket command and its response and either raises an appropriate exception or returns the formatted response.

Parameters:
  • command (str) – The command that was run.
  • response (str) – The full response string from running the command.
gen_info()[source]

Generator that yields (name, value) tuples for HAProxy info.

These values represent stats for the whole HAProxy process.

gen_stats(include_frontends, include_backends, include_servers)[source]

Generator that yields (name, values) for individual proxies.

Each tuple has two items, the proxy and a dictionary mapping stat field names to their respective values.

Parameters:
  • include_frontends (bool) – Whether or not to include FRONTEND aggregate stats.
  • include_backends (bool) – Whether or not to include BACKEND aggregate stats.
  • include_servers (bool) – Whether or not to include individual server stats.