HAProxy

Common parts of every card are described in Monitor window.
| Detected by | systemd unit haproxy, or binary haproxy |
| Read every | 15 s while the Monitor window shows the tab |
| Active probe | show info and show stat on the stats socket (off by default) |
| Test config | haproxy -c -V -f … (on demand) |
What the card shows
Section titled “What the card shows”From the configuration (passive):
- Version of the binary, Configuration files, Stats sockets (path,
level,user). - Frontends and Backends: name,
mode,balance,bindaddresses,default_backendand the backend names ofuse_backend(never its condition), servers withcheck,backup,disabled,weight. - Lua files (Test config runs their top-level code): paths of
lua-load.
From the Runtime API (active probe on): uptime, connections, threads; per frontend the state and
sessions; per backend n/m UP (red no server UP), sessions and 5xx; per server Address, State
(UP, DOWN, MAINT, …), Check (status, code, description), Since (last state change, with the
total downtime), Sessions and Weight. Backends with a problem start expanded. Without the active
probe: Live state (UP/DOWN, sessions) needs the active probe above.
How the configuration is read
Section titled “How the configuration is read”In one sh -c under one timeout (15 s) on the host:
- the files of the unit’s
-f(a directory = its*.cfgin C order, as HAProxy loads them); without a unit,CONFIGof/etc/default/haproxyor/etc/sysconfig/haproxy, otherwise/etc/haproxy/haproxy.cfg; - each file cut at 512 KiB, at most 64 files.
Lines are split into words as HAProxy does (quotes, \ escapes, # comments); a line with an
unterminated quote is skipped and reported. What leaves the host: proxy names, bind/server
addresses, mode, balance, default_backend, the backend name of use_backend, server flags,
the path, level and user of stats socket, user/uid of global, paths of lua-load, the
plain paths of bind … crt (for the TLS certificates card; crt-list only as a
flag). ACLs, headers, stats auth, userlist, peers and everything else stay on the host.
Active probe
Section titled “Active probe”Runs: show info, then show stat (only these two) on the Runtime API unix socket from stats socket in the global section, through socat -T 3 -t 3 stdio UNIX-CONNECT:<socket> (or
nc -U -w 3 <socket>), each under timeout 5. Only when the socket and every directory on its path
belong to root, this account or a HAProxy account (haproxy, user/uid of global, user of
stats socket), and no directory is writable by others unless sticky; socat/nc not
setuid/setgid. Answers are read up to 4 MiB and filtered on the host to 17 columns of show stat
(pxname, svname, type, status, check_status, check_code, check_desc, lastchg,
downtime, scur, smax, slim, weight, act, bck, hrsp_5xx, addr) and a fixed list of
show info keys (Name, Version, Release_date, Nbthread, Nbproc, Uptime_sec, Memmax_MB,
PoolUsed_MB, Maxconn, Hard_maxconn, CurrConns, CumConns, ConnRate, SessRate,
MaxSessRate, Stopping, Idle_pct).
The socket path is used only by the script on the host; it never comes back to the app to be put into a command.
Traces on the host: two connections to the stats socket per probe (they count against the
socket’s maxconn, 10 by default); HAProxy does not log CLI commands; KryoDesk’s lock file
kryodesk/haproxy.lock.
Without access to the socket (often 0660 root:haproxy) the probe stops until Retry. The
card shows the socket’s and directory’s mode, this account and its groups, and when the account is
not in the socket’s group: access needs membership (e.g. usermod -aG <group> <user>, then a new SSH
login) or a socket with another mode/group. When the socket has level admin, the card warns
that every member of that group gets full control of HAProxy (disable servers, change weights, shut
it down), not only reading. Without stats socket in the global section only the configuration is
shown.
Test config
Section titled “Test config”haproxy -c -V -f <file> … [-C <dir>] with the files of the unit’s ExecStart (-f, and keys of
the environment file such as CONFIG, EXTRAOPTS), the same as the reload uses; without them the
files of CONFIG as the last probe read them, otherwise /etc/haproxy/haproxy.cfg.
What it does, as the card says: checks the configuration the way the unit’s reload does, but without
-q, so the reason of an error is printed: reads every configuration file and every certificate and
key (crt, ca-file; usually needs root), resolves server names through DNS unless init-addr none (resolvers sections too), runs the Lua files of lua-load / lua-load-per-thread (their
top-level code), does not touch the running process.
A reload that uses -q hides the reason of a failure: systemd then shows only the exit code (the
card marks such an ExecReload). This test shows it.
Lines that may hold secrets, and the configuration excerpts HAProxy indents under its messages, are masked on the host; run the command in the terminal to see the full output.