Package: haproxyadmin
A Python library to manage HAProxy via stats socket.ContentsIntroductionFeaturesInstallationReleaseDevelopmentLicensingAcknowledgementContactsIntroductionhaproxyadminis a Python library for interacting withHAProxyload balancer to perform operations such as enabling/disabling servers.
It does that by issuing the appropriate commands over thestats socketprovided 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).haproxyadminresolves 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. TheSix Python 2 and 3 Compatibility Libraryis being used to provide the necessary wrapping over the differences between
these 2 major versions of Python.>>>fromhaproxyadminimporthaproxy>>>hap=haproxy.HAProxy(socket_dir='/run/haproxy')>>>frontends=hap.frontends()>>>forfrontendinfrontends:...print(frontend.name,frontend.requests,frontend.process_nb)...frontend_proc20[2]haproxy0[4,3,2,1]frontend_proc10[1]frontend1_proc340[4,3]frontend2_proc340[4,3]>>>>>>>>>backends=hap.backends()>>>forbackendinbackends:...print(backend.name,backend.requests,backend.process_nb)...servers=backend.servers()...forserverinservers:...print(" ",server.name,server.requests)...backend_proc2100[2]bck_proc2_srv4_proc225bck_proc2_srv3_proc225bck_proc2_srv1_proc225bck_proc2_srv2_proc225haproxy0[4,3,2,1]backend1_proc3416[4,3]bck1_proc34_srv16bck_all_srv15bck1_proc34_srv25backend_proc129[1]member2_proc114member1_proc115bck_all_srv10backend2_proc34100[4,3]bck2_proc34_srv297bck2_proc34_srv12bck_all_srv11>>>The documentation of the library is available athttp://haproxyadmin.readthedocs.orgFeaturesHAProxy in multi-process mode (nbproc >1)UNIX stats socket, no support for querying HTTP statistics pageFrontend operationsBackend operationsServer operationsACL operationsMAP operationsAggregation on various statisticsChange global options for HAProxyInstallationUse pip:pip install haproxyadminFrom Source:sudo python setup.py installBuild (source) RPMs:python setup.py clean --all; python setup.py bdist_rpmBuild a source archive for manual installation:python setup.py sdistReleaseBump versions in docs/source/conf.py and haproxyadmin/__init__.pyCommit above change with:git commit -av -m'RELEASE 0.1.3 version'Create a signed tag, pbr will use this for the version number:git tag -s 0.1.3 -m 'bump release'Create the source distribution archive (the archive will be placed in thedistdirectory):python setup.py sdistpbr will update ChangeLog file and we want to squeeze them to the previous commit thus we run:git commit -av --amendMove current tag to the last commit:git tag -fs 0.1.3 -m 'bump release'Push changes:git push;git push --tagsDevelopmentI would love to hear what other people think abouthaproxyadminand provide
feedback. Please post your comments, bug reports, wishes on myissues page.LicensingApache 2.0AcknowledgementThis 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.ContactsProject website:https://github.com/unixsurfer/haproxyadminAuthor: Pavlos Parissis <pavlos.parissis@gmail.com>