Skip to main content

A library to work with HAProxy via the stats socket

Project description

A Python library to manage HAProxy via stats socket.

Introduction

haproxyadmin is a Python library for interacting with HAProxy load balancer to perform operations such as enabling/disabling servers. It does that by issuing the appropriate commands over the stats socket provided by HAProxy. It also uses that stats socket for retrieving statistics and changing settings.

HAProxy is a multi-process daemon and each process can only be accessed by a distinct stats socket. There isn’t any shared memory for all these processes. That means that if a frontend or backend is managed by more than one processes, you have to find which stats socket you need to send the query/command. This makes the life of a sysadmin a bit difficult as he has to keep track of which stats socket to use for a given object(frontend/backend/server).

haproxyadmin resolves this problem by presenting objects as single entities even when they are managed by multiple processes. It also supports aggregation for various statistics provided by HAProxy. For instance, to report the requests processed by a frontend it queries all processes which manage that frontend and return the sum.

The library works with Python 2.7 and Python 3.6, but for development and testing Python 3.6 is used. The Six Python 2 and 3 Compatibility Library is being used to provide the necessary wrapping over the differences between these 2 major versions of Python.

>>> from haproxyadmin import haproxy
>>> hap = haproxy.HAProxy(socket_dir='/run/haproxy')
>>> frontends = hap.frontends()
>>> for frontend in frontends:
...     print(frontend.name, frontend.requests, frontend.process_nb)
...
frontend_proc2 0 [2]
haproxy 0 [4, 3, 2, 1]
frontend_proc1 0 [1]
frontend1_proc34 0 [4, 3]
frontend2_proc34 0 [4, 3]
>>>
>>>
>>> backends = hap.backends()
>>> for backend in backends:
...    print(backend.name, backend.requests, backend.process_nb)
...    servers = backend.servers()
...    for server in servers:
...       print(" ", server.name, server.requests)
...
backend_proc2 100 [2]
  bck_proc2_srv4_proc2 25
  bck_proc2_srv3_proc2 25
  bck_proc2_srv1_proc2 25
  bck_proc2_srv2_proc2 25
haproxy 0 [4, 3, 2, 1]
backend1_proc34 16 [4, 3]
  bck1_proc34_srv1 6
  bck_all_srv1 5
  bck1_proc34_srv2 5
backend_proc1 29 [1]
  member2_proc1 14
  member1_proc1 15
  bck_all_srv1 0
backend2_proc34 100 [4, 3]
  bck2_proc34_srv2 97
  bck2_proc34_srv1 2
  bck_all_srv1 1
>>>

The documentation of the library is available at http://haproxyadmin.readthedocs.org

Features

  • HAProxy in multi-process mode (nbproc >1)

  • UNIX stats socket, no support for querying HTTP statistics page

  • Frontend operations

  • Backend operations

  • Server operations

  • ACL operations

  • MAP operations

  • Aggregation on various statistics

  • Change global options for HAProxy

Installation

Use pip:

pip install haproxyadmin

From Source:

sudo python setup.py install

Build (source) RPMs:

python setup.py clean --all; python setup.py bdist_rpm

Build a source archive for manual installation:

python setup.py sdist

Release

  1. Bump versions in docs/source/conf.py and haproxyadmin/__init__.py

  2. Commit above change with:

    git commit -av -m'RELEASE 0.1.3 version'
  3. Create a signed tag, pbr will use this for the version number:

    git tag -s 0.1.3 -m 'bump release'
  4. Create the source distribution archive (the archive will be placed in the dist directory):

    python setup.py sdist
  5. pbr will update ChangeLog file and we want to squeeze them to the previous commit thus we run:

    git commit -av --amend
  6. Move current tag to the last commit:

    git tag -fs 0.1.3 -m 'bump release'
  7. Push changes:

    git push;git push --tags

Development

I would love to hear what other people think about haproxyadmin and provide feedback. Please post your comments, bug reports, wishes on my issues page.

Licensing

Apache 2.0

Acknowledgement

This program was originally developed for Booking.com. With approval from Booking.com, the code was generalised and published as Open Source on github, for which the author would like to express his gratitude.

Contacts

Project website: https://github.com/unixsurfer/haproxyadmin

Author: Pavlos Parissis <pavlos.parissis@gmail.com>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

haproxyadmin-0.2.4.tar.gz (59.0 kB view details)

Uploaded Source

File details

Details for the file haproxyadmin-0.2.4.tar.gz.

File metadata

  • Download URL: haproxyadmin-0.2.4.tar.gz
  • Upload date:
  • Size: 59.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.1

File hashes

Hashes for haproxyadmin-0.2.4.tar.gz
Algorithm Hash digest
SHA256 f22a68ae582bbd342c1bda251b69634021e2424e9d40c153d5cb1017257bfd75
MD5 97e14335586f3189a5fd7ea8eecec0b0
BLAKE2b-256 d8020d6fdcac6bb08ca3ffaeac52471bcddd8e621cdcd9168397b8cb0d5ddc46

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page