HAProxy stats from the command line
I’m currently writting a check_mk plugin to monitor HAProxy, and so wanted a way of retrieving stats without resorting to using the web interface. It turned out to be pretty easy to do, using good old netcat: /etc/haproxy/haproxy.cfg
global
[...]
stats socket /tmp/haproxy
[...]
There are plenty of options you can pass into the socket, just echo nothing into it to get the list:
$ echo "" | nc -U /tmp/haproxy
Unknown command. Please enter one of the following commands only :
clear counters : clear max statistics counters (add 'all' for all counters)
help : this message
prompt : toggle interactive mode with prompt
quit : disconnect
show info : report information about the running process
show stat : report counters for each proxy and server
[...]
And now to see the live stats:
$ echo "show stat" | nc -U /tmp/haproxy
#pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,
haproxystats,FRONTEND,,,0,0,4096,0,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,1,0,,,,0,0,0,0,,,,0,0,0,0,0,0,,0,0,0,,,
haproxystats,BACKEND,0,0,0,0,4096,0,0,0,0,0,,0,0,0,0,UP,0,0,0,,0,1014,0,,1,1,0,,0,,1,0,,0,,,,0,0,0,0,0,0,,,,,0,0,
[...]
It turns out you can make changes via this socket too, and there is even a ‘prompt’ mode to allow interactive remote configuration. HAProxy is amazing!
Read other posts