Haproxy Modules

Log

class haproxy.logfile.Log(logfile=None)
_is_pickle_valid()

Logic to decide if the file should be processed or just needs to be loaded from its pickle data.

_load()

Load data from a pickle file.

_save()

Save the attributes defined on _pickle_attributes in a pickle file.

This improves a lot the nth run as the log file does not need to be processed every time.

static _sort_and_trim(data, reverse=False)

Sorts a dictionary with at least two fields on each of them sorting by the second element.

Warning

Right now is hardcoded to 10 elements, improve the command line interface to allow to send parameters to each command or globally.

_sort_lines()

Haproxy writes its logs after having gathered all information related to each specific connection. A simple request can be really quick but others can be really slow, thus even if one connection is logged later, it could have been accepted before others that are already processed and logged.

This method sorts all valid log lines by their acceptance date, providing the real order in which connections where made to the server.

cmd_average_response_time()

Returns the average response time of all, non aborted, requests.

cmd_average_waiting_time()

Returns the average queue time of all, non aborted, requests.

cmd_connection_type()

Generates statistics on how many requests are made via HTTP and how many are made via SSL.

Note

This only works if the request path contains the default port for SSL (443).

Warning

The ports are hardcoded, they should be configurable.

cmd_counter()

Returns the number of valid lines.

cmd_counter_invalid()

Returns the number of invalid lines.

cmd_counter_slow_requests()

Counts all requests that took a certain amount of time to be processed.

Warning

By now hardcoded to 1 second (1000 milliseconds), improve the command line interface to allow to send parameters to each command or globally.

cmd_http_methods()

Reports a breakdown of how many requests have been made per HTTP method (GET, POST...).

cmd_ip_counter()

Reports a breakdown of how many requests have been made per IP.

Note

To enable this command requests need to provide a header with the forwarded IP (usually X-Forwarded-For) and be it the only header being captured.

cmd_print()

Returns the raw lines to be printed.

cmd_queue_peaks()

Generate a list of the requests peaks on the queue.

A queue peak is defined by the biggest value on the backend queue on a series of log lines that are between log lines without being queued.

Warning

Allow to configure up to which peak can be ignored. Currently set to 1.

cmd_request_path_counter()

Generate statistics about HTTP requests’ path.

cmd_requests_per_minute()

Generates statistics on how many requests were made per minute.

Note

Try to combine it with time constrains (-s and -d) as this command output can be huge otherwise.

cmd_server_load()

Generate statistics regarding how many requests were processed by each downstream server.

cmd_slow_requests()

List all requests that took a certain amount of time to be processed.

Warning

By now hardcoded to 1 second (1000 milliseconds), improve the command line interface to allow to send parameters to each command or globally.

cmd_status_codes_counter()

Generate statistics about HTTP status codes. 404, 500 and so on.

cmd_top_ips()

Returns the top most frequent IPs.

Note

See Log._sort_and_trim() for its current limitations.

cmd_top_request_paths()

Returns the top most frequent paths.

Note

See Log._sort_and_trim() for its current limitations.

classmethod commands()

Returns a list of all methods that start with cmd_.

filter(filter_func, reverse=False)

Filter current log lines by a given filter function.

This allows to drill down data out of the log file by filtering the relevant log lines to analyze.

For example, filter by a given IP so only log lines for that IP are further processed with commands (top paths, http status counter...).

Parameters:
  • filter_func (function) – [required] Filter method, see filters.py for all available filters.
  • reverse (boolean) – negate the filter (so accept all log lines that return False).
Returns:

a new instance of Log containing only log lines that passed the filter function.

Return type:

Log

TODO:
Deep copy implementation.
parse_data(logfile)

Parse data from data stream and replace object lines.

Parameters:logfile (str) – [required] Log file data stream.

Line

class haproxy.line.Line(line)

For a precise and more detailed description of every field see: http://cbonte.github.io/haproxy-dconv/configuration-1.4.html#8.2.3

accept_date = None

datetime object with the exact date when the connection to HAProxy was made.

backend_name = None

HAProxy backend that the connection was sent to.

bytes_read = None

Total number of bytes send back to the client.

client_ip = None

IP of the upstream server that made the connection to HAProxy.

client_port = None

Port used by the upstream server that made the connection to HAProxy.

connections_active = None

Total number of concurrent connections on the process when the session was logged (actconn in HAProxy documentation).

connections_backend = None

Total number of concurrent connections handled by the backend when the session was logged (beconn in HAProxy documentation).

connections_frontend = None

Total number of concurrent connections on the frontend when the session was logged (feconn in HAProxy documentation).

connections_server = None

Total number of concurrent connections still active on the server when the session was logged (srv_conn in HAProxy documentation).

frontend_name = None

HAProxy frontend that received the connection.

get_ip()

Returns the IP provided on the log line.

http_request_method = None

HTTP method (GET, POST...) used on this request.

http_request_path = None

Requested HTTP path.

http_request_protocol = None

HTTP version used on this request.

is_https()

Returns True if the log line is a SSL connection. False otherwise.

queue_backend = None

Total number of requests which were processed before this one in the backend’s global queue (backend_queue in HAProxy documentation).

queue_server = None

Total number of requests which were processed before this one in the server queue (srv_queue in HAProxy documentation).

retries = None

Number of connection retries experienced by this session when

server_name = None

Downstream server that HAProxy send the connection to.

status_code = None

HTTP status code returned to the client.

time_connect_server = None

Time in milliseconds to connect to the final server (Tc in HAProxy documentation).

time_wait_queues = None

Time in milliseconds that the request spend on HAProxy queues (Tw in HAProxy documentation).

time_wait_request = None

Time in milliseconds waiting the client to send the full HTTP request (Tq in HAProxy documentation).

time_wait_response = None

Time in milliseconds waiting the downstream server to send the full HTTP response (Tr in HAProxy documentation).

total_time = None

Total time in milliseconds between accepting the HTTP request and sending back the HTTP response (Tt in HAProxy documentation).