### Install haproxyadmin from source Source: https://haproxyadmin.readthedocs.io/en/latest/introduction.html Installs the library from source using setup.py. ```bash sudo python setup.py install ``` -------------------------------- ### Install haproxyadmin with pip Source: https://haproxyadmin.readthedocs.io/en/latest/introduction.html Installs the haproxyadmin library using pip. ```bash pip install haproxyadmin ``` -------------------------------- ### Example output of utils.info2dict Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Shows the dictionary structure generated from the 'show info' command output. ```python { Name: HAProxy Version: 1.4.24 Release_date: 2013/06/17 Nbproc: 1 Process_num: 1 Pid: 1155 Uptime: 5d 4h42m16s Uptime_sec: 448936 Memmax_MB: 0 Ulimit-n: 131902 Maxsock: 131902 Maxconn: 65536 Maxpipes: 0 CurrConns: 1 PipesUsed: 0 PipesFree: 0 Tasks: 819 Run_queue: 1 node: node1 description: } ``` -------------------------------- ### Get all servers across all backends Source: https://haproxyadmin.readthedocs.io/en/latest/user/backend.html Iterates over all backends from hap.backends() and prints backend name, requests, process_nb, and then each server's name and requests. The output shows multiple backends and their servers. ```python >>> for backend in backends: >>> backends = hap.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 >>> ``` -------------------------------- ### Check if a backend exists Source: https://haproxyadmin.readthedocs.io/en/latest/user/backend.html Uses the hap.backends() method to get a list of backends and checks membership with the 'in' operator. The example shows that 'backend1_proc34' is present and prints 'have it', while 'backend1_proc34foo' is not and produces no output. ```python >>> backends = hap.backends() >>> if 'backend1_proc34' in backends: ... print('have it') ... have it >>> if 'backend1_proc34foo' in backends: ... print('have it') ... >>> ``` -------------------------------- ### Retrieve total frontend requests Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Demonstrates how to get the total number of requests for a specific frontend. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> frontend = hap.frontend('frontend2_proc34') >>> frontend.requests 5 ``` -------------------------------- ### Get server status with check_status and status Source: https://haproxyadmin.readthedocs.io/en/latest/user/server.html Retrieves the status of a server using attributes like last_agent_check, check_status, check_code, and status. The example shows a server in 'DOWN' state with check_status 'L4TOUT'. ```python >>> backend = hap.backend('backend1_proc34') >>> server = backend.server('bck_all_srv1') >>> server.last_agent_check '' >>> server.check_status 'L4TOUT' >>> server.check_ server.check_code server.check_status >>> server.check_code '' >>> server.status 'DOWN' >>> ``` -------------------------------- ### Example structure of utils.stat2dict Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Shows the nested dictionary structure generated from 'show stat' CSV data. ```python { 'backends': { 'acq-misc': { 'stats': { _CSVLine object }, 'servers': { 'acqrdb-01': { _CSVLine object }, 'acqrdb-02': { _CSVLine object }, ... } }, ... }, 'frontends': { 'acq-misc': { _CSVLine object }, ... }, ... } ``` -------------------------------- ### Get a specific server from a backend Source: https://haproxyadmin.readthedocs.io/en/latest/user/backend.html Uses backend.server('bck1_proc34_srv2') to retrieve a server object and prints its name, backendname, status, requests, and weight. The output shows the server is UP with 9 requests and weight 1. ```python >>> s1 = backend.server('bck1_proc34_srv2') >>> s1.name, s1.backendname, s1.status, s1.requests, s1.weight ('bck1_proc34_srv2', 'backend1_proc34', 'UP', 9, 1) ``` -------------------------------- ### Get servers of a specific backend Source: https://haproxyadmin.readthedocs.io/en/latest/user/backend.html Gets a backend object and iterates over its servers, printing name, status, and weight. The output shows three servers all with status UP and weight 1. ```python >>> backend = hap.backend('backend1_proc34') >>> for s in backend.servers(): ... print(s.name, s.status, s.weight) ... bck1_proc34_srv2 UP 1 bck_all_srv1 UP 1 bck1_proc34_srv1 UP 1 >>> ``` -------------------------------- ### CSVLine Usage Example Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Demonstrates how to use the CSVLine class to map CSV field values to object attributes based on a provided header list. ```python >>> from haproxyadmin import utils >>> heads = ['pxname', 'type', 'lbtol'] >>> parts = ['foor', 'backend', '444'] >>> utils.CSVLine.heads = heads >>> csvobj = utils.CSVLine(parts) >>> csvobj.pxname 'foor' >>> csvobj.type 'backend' >>> csvobj.lbtol '444' >>> csvobj.bar Traceback (most recent call last): File "", line 1, in File "/.../haproxyadmin/haproxyadmin/utils.py", line 341, in __getattr__ _index = self.heads.index(attr) ValueError: 'bar' is not in list ``` -------------------------------- ### Get HAProxy uptime Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns the uptime of the HAProxy process as a formatted string. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.uptime '4d 0h16m26s' ``` -------------------------------- ### Get HAProxy version Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns the version string of the HAProxy process. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.version '1.5.8' ``` -------------------------------- ### Retrieve backend statistics with BACKEND_METRICS Source: https://haproxyadmin.readthedocs.io/en/latest/user/backend.html Gets a backend object via hap.backend('backend1_proc34') and iterates over BACKEND_METRICS to print each metric name and value. The output shows values for metrics like act, bck, downtime, and weight. Also demonstrates accessing process_nb, requests_per_process(), and requests attributes. ```python >>> backend = hap.backend('backend1_proc34') >>> for m in BACKEND_METRICS: ... print("name {} value {}".format(m, backend.metric(m))) ... name act value 3 name bck value 0 name bin value 0 name bout value 0 name chkdown value 2 name cli_abrt value 0 name comp_byp value 0 name comp_in value 0 name comp_out value 0 name comp_rsp value 0 name ctime value 0 name downtime value 8237 name dreq value 0 name dresp value 0 name econ value 0 name eresp value 0 name hrsp_1xx value 0 name hrsp_2xx value 0 name hrsp_3xx value 0 name hrsp_4xx value 0 name hrsp_5xx value 0 name hrsp_other value 0 name lastchg value 11373 name lastsess value -1 name lbtot value 0 name qcur value 0 name qmax value 0 name qtime value 0 name rate value 0 name rate_max value 0 name rtime value 0 name scur value 0 name slim value 200000 name smax value 0 name srv_abrt value 0 name stot value 0 name ttime value 0 name weight value 3 name wredis value 0 name wretr value 0 >>> >>> >>> backend.process_nb [4, 3] >>> backend.requests_per_process() [(4, 2), (3, 3)] >>> backend.requests 5 >>> ``` -------------------------------- ### Change maximum connections for a specific frontend Source: https://haproxyadmin.readthedocs.io/en/latest/user/frontend.html Changes the maximum connections for a specific frontend by name. The example shows the initial maxconn, the setmaxconn() call returning True, and the updated maxconn value. ```python >>> frontend = hap.frontend('frontend1_proc34') >>> frontend.maxconn 20000 >>> frontend.setmaxconn(50000) True >>> frontend.maxconn 100000 ``` -------------------------------- ### Get HAProxy uptime in seconds Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns the uptime of the HAProxy process as an integer representing seconds. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.uptimesec 346588 ``` -------------------------------- ### Using haproxyadmin to list frontends and backends Source: https://haproxyadmin.readthedocs.io/en/latest/introduction.html Shows how to instantiate HAProxy and iterate over frontends and backends, printing their names, request counts, and process numbers. The output demonstrates the aggregated statistics across multiple HAProxy processes. ```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 >>> ``` -------------------------------- ### Build source archive for haproxyadmin Source: https://haproxyadmin.readthedocs.io/en/latest/introduction.html Creates a source distribution archive using setup.py sdist. ```bash python setup.py sdist ``` -------------------------------- ### Initialize and view MAPs Source: https://haproxyadmin.readthedocs.io/en/latest/user/haproxy.html Initialize the HAProxy connection and display MAP entries. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_map(map=6) ['# id (file) description', "0 (/etc/haproxy/v-m1-bk) pattern loaded ...... line 82", ''] >>> hap.show_map(0) ['0x1a78ab0 0 www.foo.com-0', '0x1a78b20 1 www.foo.com-1', ''] ``` -------------------------------- ### Server.port property Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Gets or sets the assigned port of the server. ```APIDOC ## Server.port property ### Description Gets or sets the assigned port of the server. ### Getter Returns the port as a string. ### Setter Sets the port. Parameters: port (string) - port to set. Returns bool. ``` -------------------------------- ### _Frontend.__init__(hap_process, name, iid) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Constructor for the _Frontend class. Initializes a frontend object associated with a single HAProxy process. ```APIDOC ## _Frontend.__init__(hap_process, name, iid) ### Description Constructor for the _Frontend class. Initializes a frontend object associated with a single HAProxy process. ### Parameters - **hap_process** (_HAProxyProcess) - Required - A _HAProxyProcess object. - **name** (string) - Required - Frontend name. - **iid** (integer) - Required - Unique proxy id of the frontend. ``` -------------------------------- ### Server.address property Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Gets or sets the assigned address of the server. ```APIDOC ## Server.address property ### Description Gets or sets the assigned address of the server. ### Getter Returns the address as a string. ### Setter Sets the address. Parameters: address (string) - address to set. Returns bool. ``` -------------------------------- ### Retrieve frontend requests per process Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Demonstrates how to initialize an HAProxy instance, select a specific frontend, and retrieve the number of requests per process. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> frontend = hap.frontend('frontend2_proc34') >>> frontend.requests_per_process() [(4, 2), (3, 3)] ``` -------------------------------- ### _Frontend.command(cmd) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Runs a command to HAProxy and returns the first line of the output. ```APIDOC ## _Frontend.command(cmd) ### Description Runs a command to HAProxy and returns the first line of the output. ### Parameters - **cmd** (string) - Required - A valid command to execute. ### Returns - **string** - 1st line of the output. ``` -------------------------------- ### HAProxy.__init__ Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Constructor for the HAProxy object, the main interface to interact with HAProxy. ```APIDOC ## HAProxy.__init__ ### Description Build a user-created HAProxy object for HAProxy. This is the main class to interact with HAProxy and provides methods to create objects for managing frontends, backends and servers. It also provides an interface to interact with HAProxy as a way to retrieve settings/statistics but also change settings. ACLs and MAPs are also managed by HAProxy class. ### Method Constructor ### Signature `HAProxy(socket_dir=None, socket_file=None, retry=2, retry_interval=2)` ### Parameters - **socket_dir** (string) - Optional - A directory with HAProxy stats files. - **socket_file** (string) - Optional - Absolute path of HAProxy stats file. - **retry** (integer or None) - Optional - Number of times to retry to open a UNIX socket connection after a failure occurred. Possible values: None => don't retry, 0 => retry indefinitely, 1..N => times to retry. - **retry_interval** (integer) - Optional - Sleep time between the retries. ### Returns - **HAProxy** - A user-created HAProxy object. ``` -------------------------------- ### Get total frontend requests Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns the total number of requests processed by all frontends. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.requests 457 ``` -------------------------------- ### Get HAProxy release date Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Retrieves the release date of the HAProxy process as a string. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.releasedate '2014/10/31' ``` -------------------------------- ### info2dict(raw_info) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Builds a dictionary structure from the output of the 'show info' command. The input is a list of raw data lines, and the output is a dictionary with keys like Name, Version, Pid, etc. ```APIDOC ## info2dict(raw_info) ### Description Builds a dictionary structure from the output of the 'show info' command. ### Parameters - **raw_info** (list) - Required - Data returned by the 'show info' UNIX socket command. ### Returns - **dict** - A dictionary with keys/values as shown in the example below. ### Example Output ``` { Name: HAProxy Version: 1.4.24 Release_date: 2013/06/17 Nbproc: 1 Process_num: 1 Pid: 1155 Uptime: 5d 4h42m16s Uptime_sec: 448936 Memmax_MB: 0 Ulimit-n: 131902 Maxsock: 131902 Maxconn: 65536 Maxpipes: 0 CurrConns: 1 PipesUsed: 0 PipesFree: 0 Tasks: 819 Run_queue: 1 node: node1 description: } ``` ``` -------------------------------- ### Build source RPMs for haproxyadmin Source: https://haproxyadmin.readthedocs.io/en/latest/introduction.html Builds source RPMs by cleaning and running bdist_rpm. ```bash python setup.py clean --all; python setup.py bdist_rpm ``` -------------------------------- ### server(hostname, backend=None) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Builds Server objects for a given server hostname. If a backend is specified, the lookup is limited to that backend. Returns a list of Server objects. ```APIDOC ## server(hostname, backend=None) ### Description Build Server objects for a given server. If backend is specified, lookup is limited to that backend. If a server is a member of more than one backend, multiple objects for the same server are returned. ### Method N/A (Python method) ### Parameters - **hostname** (string) - Required - Servername to look for. - **backend** (string) - Optional - Backend name to look in. ### Returns - A list of Server objects. ### Return Type list ``` -------------------------------- ### servers(backend=None) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Builds Server objects for each server. If a backend is specified, the lookup is limited to that backend. Returns a list of Server objects. ```APIDOC ## servers(backend=None) ### Description Build Server objects for each server. If backend is specified, lookup is limited to that backend. ### Method N/A (Python method) ### Parameters - **backend** (string) - Optional - Backend name. ### Returns - A list of Server objects. ### Return Type list ``` -------------------------------- ### Set Server State with setstate Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Demonstrates how to disable and enable a server using the setstate method and the corresponding state constants. ```python >>> from haproxyadmin import haproxy, STATE_DISABLE, STATE_ENABLE >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> server = hap.server('member_bkall', backend='backend_proc1')[0] >>> server.setstate(haproxy.STATE_DISABLE) True >>> server.status 'MAINT' >>> server.setstate(haproxy.STATE_ENABLE) True >>> server.status 'no check' ``` -------------------------------- ### Get total cumulative requests Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns the total cumulative number of requests processed by all processes, including both frontends and backends. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.totalrequests 457 ``` -------------------------------- ### List all frontend objects Source: https://haproxyadmin.readthedocs.io/en/latest/user/haproxy.html Retrieve a list of all available frontend objects. ```python >>> frontends = hap.frontends() >>> for f in frontends: ... print(f.name) ... frontend_proc1 haproxy frontend1_proc34 frontend2_proc34 frontend_proc2 ``` -------------------------------- ### Retrieve frontend process numbers Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Demonstrates how to list the process numbers where a specific frontend is configured. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> frontend = hap.frontend('frontend2_proc34') >>> frontend.process_nb [4, 3] ``` -------------------------------- ### Check if a frontend exists Source: https://haproxyadmin.readthedocs.io/en/latest/user/frontend.html Use the hap.frontends() method to get a list of frontend names and check if a specific frontend exists. ```APIDOC ## Check if a frontend exists ### Description Use the `hap.frontends()` method to retrieve a list of frontend names and check if a specific frontend exists. ### Method `hap.frontends()` ### Parameters None ### Returns A list of frontend names. ### Example ```python >>> frontends = hap.frontends() >>> if 'frontend2_proc34' in frontends: ... print('have it') ... have it ``` ``` -------------------------------- ### info() Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Dump info about haproxy stats on current process. ```APIDOC ## info() ### Description Dump info about haproxy stats on current process. ### Returns A list of dict for each process. ### Return Type list ``` -------------------------------- ### HAProxy ACL Management Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Demonstrates initializing the HAProxy object and performing basic ACL operations like adding and showing entries. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.command('show stats') ['0x23181c0 /static/css/'] >>> hap.add_acl(acl=4, pattern='/foo/' ) True >>> hap.show_acl(acl=4) ['0x23181c0 /static/css/', '0x238f790 /foo/'] ``` -------------------------------- ### Terminate server sessions with server.shutdown() Source: https://haproxyadmin.readthedocs.io/en/latest/user/server.html Terminates all sessions attached to a server using server.shutdown(). The example shows the current session count (scur) dropping from 8 to 0 after shutdown. ```python >>> backend = hap.backend('backend1_proc34') >>> server = backend.server('bck_all_srv1') >>> server.metric('scur') 8 >>> server.shutdown() True >>> server.metric('scur') 0 ``` -------------------------------- ### Initialize HAProxy object Source: https://haproxyadmin.readthedocs.io/en/latest/user/guide.html Create a HAProxy object named 'hap' to interact with HAProxy processes. Ensure you have write permissions for the specified socket directory. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') ``` -------------------------------- ### Frontend.enable(die) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Enables the frontend. Returns True if successful, otherwise False. If die is True, raises CommandFailed or MultipleCommandResults on error. ```APIDOC ## Frontend.enable(die) ### Description Enable the frontend. ### Method Python method ### Signature `enable(die)` ### Parameters - **die** (bool) - control the handling of errors. ### Returns - **bool** - True if frontend is enabled otherwise False. ### Raises - `haproxyadmin.exceptions.CommandFailed` or `haproxyadmin.exceptions.MultipleCommandResults` if die is True and something bad happens, otherwise returns False. ``` -------------------------------- ### _Server(backend, name, sid) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Constructor for the _Server class. Creates an object to interact with a server of a backend in one HAProxy. ```APIDOC ## _Server(backend, name, sid) ### Description Class for interacting with a server of a backend in one HAProxy. ### Parameters - **backend** - a _Backend object in which server is part of. - **name** (string) - server name. - **sid** (string) - server id (unique inside a proxy). ``` -------------------------------- ### Manage a specific server across all backends Source: https://haproxyadmin.readthedocs.io/en/latest/user/haproxy.html Iterate through all instances of a server across different backends and update their state. ```python >>> s1 = hap.server(hostname='bck_all_srv1') >>> for x in s1: ... print(x.name, x.backendname, x.status) ... x.setstate(haproxy.STATE_DISABLE) ... print(x.status) ... bck_all_srv1 backend1_proc34 DOWN True MAINT bck_all_srv1 backend_proc1 DOWN True MAINT bck_all_srv1 backend2_proc34 no check True MAINT ``` -------------------------------- ### List all backend objects Source: https://haproxyadmin.readthedocs.io/en/latest/user/haproxy.html Retrieve a list of all available backend objects. ```python >>> backends = hap.backends() >>> for b in backends: ... print(b.name) ... haproxy backend1_proc34 backend_proc2 backend_proc1 backend2_proc34 ``` -------------------------------- ### HAProxy.backend Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Build a Backend object. ```APIDOC ## HAProxy.backend ### Description Build a Backend object. ### Method backend ### Signature `backend(name)` ### Parameters - **name** (string) - Required - Backend name to look up. ### Raises - ValueError when backend isn't found or more than 1 backend is found. ``` -------------------------------- ### HAProxy.backends Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Build a list of Backend objects. ```APIDOC ## HAProxy.backends ### Description Build a list of Backend objects. ### Method backends ### Signature `backends(name=None)` ### Parameters - **name** (string) - Optional - Backend name to look up. ### Returns - **list** - List of Backend objects. ``` -------------------------------- ### Retrieve server statistics with backend.servers() and server.metric() Source: https://haproxyadmin.readthedocs.io/en/latest/user/server.html Iterates over all servers in a backend and prints each server's name and all metrics from SERVER_METRICS using server.metric(). The output shows the metric names and values for each server. ```python >>> backend = hap.backend('backend1_proc34') >>> for server in backend.servers(): ... print(server.name) ... for m in SERVER_METRICS: ... print("name {} value {}".format(m, server.metric(m))) ... print("-----------") ... bck1_proc34_srv2 name qcur value 0 name qmax value 0 name scur value 0 name smax value 0 name stot value 0 name bin value 0 name bout value 0 name dresp value 0 name econ value 0 name eresp value 0 name wretr value 0 name wredis value 0 name weight value 1 name act value 1 name bck value 0 name chkfail value 6 name chkdown value 4 name lastchg value 39464 name downtime value 47702 name qlimit value 0 name throttle value 0 name lbtot value 0 name rate value 0 name rate_max value 0 name check_duration value 5001 name hrsp_1xx value 0 name hrsp_2xx value 0 name hrsp_3xx value 0 name hrsp_4xx value 0 name hrsp_5xx value 0 name hrsp_other value 0 name cli_abrt value 0 name srv_abrt value 0 name lastsess value -1 name qtime value 0 name ctime value 0 name rtime value 0 name ttime value 0 ----------- bck1_proc34_srv1 name qcur value 0 name qmax value 0 name scur value 0 name smax value 0 name stot value 0 name bin value 0 name bout value 0 name dresp value 0 name econ value 0 name eresp value 0 name wretr value 0 name wredis value 0 name weight value 1 name act value 1 name bck value 0 name chkfail value 6 name chkdown value 4 name lastchg value 39464 name downtime value 47702 name qlimit value 0 name throttle value 0 name lbtot value 0 name rate value 0 name rate_max value 0 name check_duration value 5001 name hrsp_1xx value 0 name hrsp_2xx value 0 name hrsp_3xx value 0 name hrsp_4xx value 0 name hrsp_5xx value 0 name hrsp_other value 0 name cli_abrt value 0 name srv_abrt value 0 name lastsess value -1 name qtime value 0 name ctime value 0 name rtime value 0 name ttime value 0 ----------- bck_all_srv1 name qcur value 0 name qmax value 0 name scur value 0 name smax value 0 name stot value 0 name bin value 0 name bout value 0 name dresp value 0 name econ value 0 name eresp value 0 name wretr value 0 name wredis value 0 name weight value 1 name act value 1 name bck value 0 name chkfail value 6 name chkdown value 4 name lastchg value 39462 name downtime value 47700 name qlimit value 0 name throttle value 0 name lbtot value 0 name rate value 0 name rate_max value 0 name check_duration value 5001 name hrsp_1xx value 0 name hrsp_2xx value 0 name hrsp_3xx value 0 name hrsp_4xx value 0 name hrsp_5xx value 0 name hrsp_other value 0 name cli_abrt value 0 name srv_abrt value 0 name lastsess value -1 name qtime value 0 name ctime value 0 name rtime value 0 name ttime value 0 ----------- >>> ``` -------------------------------- ### _Backend.command(cmd) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Sends a command to HAProxy and returns the output. ```APIDOC ## _Backend.command(cmd) ### Description Send command to HAProxy. ### Parameters - **cmd** (string) - command to send. ### Returns - The output of the command (string). ``` -------------------------------- ### _Backend.servers(name=None) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns a list of _Server objects for each server of the backend. ```APIDOC ## _Backend.servers(name=None) ### Description Return a list of _Server objects for each server of the backend. ### Parameters - **name** (string) - (optional) server name to lookup, defaults to None. ### Returns - List of _Server objects. ``` -------------------------------- ### List all server objects Source: https://haproxyadmin.readthedocs.io/en/latest/user/haproxy.html Retrieve a list of all server objects. If a server is a member of multiple backends, multiple objects are returned for that server. ```python >>> servers = hap.servers() >>> for s in servers: ... print(s.name, s.backendname) ... bck1_proc34_srv1 backend1_proc34 bck1_proc34_srv2 backend1_proc34 bck_all_srv1 backend1_proc34 bck_proc2_srv3_proc2 backend_proc2 bck_proc2_srv1_proc2 backend_proc2 bck_proc2_srv4_proc2 backend_proc2 bck_proc2_srv2_proc2 backend_proc2 member1_proc1 backend_proc1 bck_all_srv1 backend_proc1 member2_proc1 backend_proc1 bck2_proc34_srv1 backend2_proc34 bck_all_srv1 backend2_proc34 bck2_proc34_srv2 backend2_proc34 ``` -------------------------------- ### _Backend(hap_process, name, iid) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Constructor for the _Backend class. Creates an object to interact with a backend in a single HAProxy process. ```APIDOC ## _Backend(hap_process, name, iid) ### Description Class for interacting with a backend in one HAProxy process. ### Parameters - **hap_process** - a HAProxyProcess object. - **name** (string) - backend name. - **iid** (integer) - unique proxy id of the backend. ``` -------------------------------- ### Retrieve frontend status Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Demonstrates how to check the current status of a frontend. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> frontend = hap.frontend('frontend2_proc34') >>> frontend.status 'OPEN' ``` -------------------------------- ### Backend.server(name) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns a Server object for the specified server name. ```APIDOC ## Backend.server(name) ### Description Returns a Server object for the specified server name. ### Method server ### Parameters - **name** (string) - Required - Name of the server ### Returns Server object ### Return Type haproxyadmin.Server ``` -------------------------------- ### frontend(name) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Build a Frontend object for the given frontend name. Raises ValueError if not found or more than one found. ```APIDOC ## frontend(name) ### Description Build a Frontend object. ### Parameters - **name** (string) - Required - frontend name to look up. ### Returns A Frontend object for the frontend. ### Return Type Frontend ### Raises ValueError when frontend isn't found or more than 1 frontend is found. ``` -------------------------------- ### Backend.servers(name=None) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns a list of Server objects for each server, optionally filtered by name. ```APIDOC ## Backend.servers(name=None) ### Description Returns Server object for each server, optionally filtered by name. ### Method servers ### Parameters - **name** (string) - Optional - servername to look for. Defaults to None. ### Returns A list of Server objects ### Return Type list ``` -------------------------------- ### Convert values with utils.converter Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Demonstrates converting input values to integers or strings, returning None for invalid conversions. ```python >>> from haproxyadmin import utils >>> utils.converter('0') 0 >>> utils.converter('13.5') 13 >>> utils.converter('13.5f') '13.5f' >>> utils.converter('') >>> utils.converter(' ') >>> utils.converter('UP') 'UP' >>> utils.converter('UP 1/2') 'UP 1/2' >>> ``` -------------------------------- ### Create signed tag for release Source: https://haproxyadmin.readthedocs.io/en/latest/introduction.html Creates a signed tag for the release version. ```bash git tag -s 0.1.3 -m 'bump release' ``` -------------------------------- ### Server.name property Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns the name of the server. ```APIDOC ## Server.name property ### Description Returns the name of the server. ### Return Type string ``` -------------------------------- ### backends(name=None) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Builds backend objects for each backend. Optionally filters by backend name. ```APIDOC ## backends(name=None) ### Description Builds backend objects for each backend. Optionally filters by backend name. ### Parameters - **name** (string) - Optional - Backend name, defaults to None ### Returns - A list of backend objects for each backend (type: list) ``` -------------------------------- ### frontends(name=None) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Build a list of Frontend objects, optionally filtered by a given frontend name. ```APIDOC ## frontends(name=None) ### Description Build a list of Frontend objects. ### Parameters - **name** (string) - Optional - frontend name to look up. ### Returns List of Frontend objects. ### Return Type list ``` -------------------------------- ### Disable and enable a frontend Source: https://haproxyadmin.readthedocs.io/en/latest/user/frontend.html Disables and then enables a frontend. The status changes from 'OPEN' to 'STOP' after disable() and back to 'OPEN' after enable(), with both methods returning True. ```python >>> frontend = hap.frontend('frontend1_proc34') >>> frontend.status 'OPEN' >>> frontend.disable() True >>> frontend.status 'STOP' >>> frontend.enable() True >>> frontend.status 'OPEN' ``` -------------------------------- ### proc_info() Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns a dictionary containing information about the HAProxy daemon. ```APIDOC ## proc_info() ### Description Returns a dictionary containing information about the HAProxy daemon. ### Returns - A dictionary (see utils.info2dict() for details) ``` -------------------------------- ### Change server weight across all backends with hap.server() Source: https://haproxyadmin.readthedocs.io/en/latest/user/server.html Changes the weight of a server across all backends using hap.server() and server.setweight(). The loop prints the backend name and weight before and after setting the weight to 8. ```python >>> server_per_backend = hap.server('bck_all_srv1') >>> for server in server_per_backend: ... print(server.backendname, server.weight) ... server.setweight(8) ... print(server.backendname, server.weight) ... backend2_proc34 1 True backend2_proc34 8 backend1_proc34 0 True backend1_proc34 8 backend_proc1 100 True backend_proc1 8 >>> ``` -------------------------------- ### _Frontend.stats() Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Builds a dictionary for all statistics reported by HAProxy. ```APIDOC ## _Frontend.stats() ### Description Builds a dictionary for all statistics reported by HAProxy. ### Returns - **dict** - A dictionary with statistics. ``` -------------------------------- ### command(command, full_output=False) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Sends a command to HAProxy over UNIX stats socket. Returns the first line of output or the full output as a list. ```APIDOC ## command(command, full_output=False) ### Description Sends a command to HAProxy over UNIX stats socket. Newline characters are stripped. ### Parameters - **command** (string) - Required - A valid command to execute - **full_output** (bool) - Optional - Return all output, by default returns only the 1st line of the output ### Returns - 1st line of the output (string) or the whole output as a list if full_output is True ``` -------------------------------- ### version Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns the version of HAProxy. ```APIDOC ## version ### Description Return version of HAProxy. ### Method Property (read-only) ### Return Type string ### Usage ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.version '1.5.8' ``` ``` -------------------------------- ### _Server.stats() Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Builds a dictionary for all statistics reported by HAProxy. ```APIDOC ## _Server.stats() ### Description Build dictionary for all statistics reported by HAProxy. ### Returns - A dictionary with statistics (dict). ``` -------------------------------- ### Frontend.stats_per_process() Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns all stats of the frontend per process as a list of tuples. ```APIDOC ## Frontend.stats_per_process() ### Description Return all stats of the frontend per process. ### Method Python method ### Signature `stats_per_process()` ### Returns - **list** - a list of tuples with 2 elements: 1. process number, 2. a dict with all stats ``` -------------------------------- ### _Backend.stats() Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Builds a dictionary for all statistics reported by HAProxy. ```APIDOC ## _Backend.stats() ### Description Build dictionary for all statistics reported by HAProxy. ### Returns - A dictionary with statistics (dict). ``` -------------------------------- ### Change server weight with server.setweight() Source: https://haproxyadmin.readthedocs.io/en/latest/user/server.html Changes the weight of a server in a backend using server.setweight(). A value ending with '%' sets the weight relative to the initially configured weight; absolute weights are allowed between 0 and 256. ```python >>> backend = hap.backend('backend1_proc34') >>> server = backend.server('bck_all_srv1') >>> server.weight 100 >>> server.setweight('20%') True >>> server.weight 20 >>> server.setweight(58) True >>> server.weight 58 ``` -------------------------------- ### Server.process_nb property Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns a list of process numbers in which the backend server is configured. ```APIDOC ## Server.process_nb property ### Description Returns a list of process numbers in which the backend server is configured. ### Return Type list ``` -------------------------------- ### Frontend.name Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns the name of the frontend. ```APIDOC ## Frontend.name ### Description Return the name of the frontend. ### Returns - **string** - return type ``` -------------------------------- ### Add an entry to a map Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Demonstrates adding a key-value pair to a map using the add_map method. ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_map(0) ['0x1a78b20 1 www.foo.com-1'] >>> hap.add_map(0, '9', 'foo') True >>> hap.show_map(0) ['0x1a78b20 1 www.foo.com-1', '0x1b15c80 9 foo'] ``` -------------------------------- ### Change maximum connections for all frontends Source: https://haproxyadmin.readthedocs.io/en/latest/user/frontend.html Iterates over all frontends and changes the maximum connections to 10000 using setmaxconn(). The output shows the before and after maxconn values for each frontend, with setmaxconn() returning True. ```python >>> frontends = hap.frontends() >>> for f in frontends: ... print(f.maxconn, f.name) ... f.setmaxconn(10000) ... print(f.maxconn, f.name) ... print('---------------') ... 3000 haproxy-stats2 True 10000 haproxy-stats2 --------------- 6000 frontend1_proc34 True 20000 frontend1_proc34 --------------- 6000 frontend2_proc34 True 20000 frontend2_proc34 --------------- 3000 frontend_proc2 True 10000 frontend_proc2 --------------- 3000 haproxy-stats True 10000 haproxy-stats --------------- 3000 haproxy-stats3 True 10000 haproxy-stats3 --------------- 3000 haproxy-stats4 True 10000 haproxy-stats4 --------------- 3000 frontend_proc1 True 10000 frontend_proc1 --------------- ``` -------------------------------- ### Frontend.process_nb Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns a list of process numbers in which the frontend is configured. ```APIDOC ## Frontend.process_nb ### Description Return a list of process number in which frontend is configured. ### Returns - **list** - return type ### Usage Example ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> frontend = hap.frontend('frontend2_proc34') >>> frontend.process_nb [4, 3] ``` ``` -------------------------------- ### uptime Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns the uptime of the HAProxy process. ```APIDOC ## uptime ### Description Return uptime of HAProxy process. ### Method Property (read-only) ### Return Type string ### Usage ```python >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.uptime '4d 0h16m26s' ``` ``` -------------------------------- ### Backend.name Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns the name of the backend. ```APIDOC ## Backend.name ### Description Returns the name of the backend. ### Return Type string ``` -------------------------------- ### haproxyadmin.FRONTEND_METRICS Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html A list of metric names for retrieving various statistics for frontends. ```APIDOC ## haproxyadmin.FRONTEND_METRICS ### Description A list of metric names for retrieving various statistics for frontends. ### Type list ``` -------------------------------- ### Server.stats_per_process() Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Returns all stats of the server per process. ```APIDOC ## Server.stats_per_process() ### Description Returns all stats of the server per process. ### Method stats_per_process ### Return Type A list of tuple 2 elements: 1. process number, 2. a dict with all stats. ``` -------------------------------- ### _HAProxyProcess(socket_file, retry=3, retry_interval=2) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Constructor for creating an object to communicate with a single HAProxy process via a UNIX stats socket. It accepts the socket file path and optional retry settings. ```APIDOC ## _HAProxyProcess(socket_file, retry=3, retry_interval=2) ### Description Creates an object to communicate with a single HAProxy process via a UNIX stats socket. ### Parameters - **socket_file** (string) - Required - Full path of socket file. - **retry** (integer) - Optional - Number of connect retries (defaults to 3) - **retry_interval** (integer) - Optional - Interval time in seconds between retries (defaults to 2) ``` -------------------------------- ### HAProxy.command Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Send a command to the HAProxy process. ```APIDOC ## HAProxy.command ### Description Send a command to the HAProxy process. This allows a user to send any kind of command to haproxy. No sanitization is performed on input or output. ### Method command ### Signature `command(cmd)` ### Parameters - **cmd** (string) - Required - A command to send to haproxy process. ### Returns - **list** - List of 2-item tuples: (HAProxy process number, what the method returned). ``` -------------------------------- ### show_map(mapid=None) Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Dumps info about maps. Without an argument, returns the list of all available maps. If a mapid is specified, its contents are dumped. Returns a list. ```APIDOC ## show_map(mapid=None) ### Description Dump info about maps. Without argument, the list of all available maps is returned. If a mapid is specified, its contents are dumped. ### Method N/A (Python method) ### Parameters - **mapid** (integer or string) - Optional - Map id or a file path. ### Returns - A list with the maps. ### Return Type list ### Usage Example ``` >>> from haproxyadmin import haproxy >>> hap = haproxy.HAProxy(socket_dir='/run/haproxy') >>> hap.show_map() ['# id (file) description', "0 (/etc/haproxy/v-m1-bk) pattern loaded ...... line 82", ] >>> hap.show_map(mapid=0) ['0x1a78ab0 0 www.foo.com-0', '0x1a78b20 1 www.foo.com-1'] ``` ``` -------------------------------- ### _Server.sid Source: https://haproxyadmin.readthedocs.io/en/latest/dev/api.html Property that returns the server id. ```APIDOC ## _Server.sid ### Description Return server id. ```