how to view haproxy status on the command line using a socket

39,456

I found the following to be useful

watch 'echo "show stat" | nc -U /var/lib/haproxy/stats | cut -d "," -f 1,2,5-11,18,24,27,30,36,50,37,56,57,62 | column -s, -t'

It will produce output as follows

Every 2.0s: echo "show stat" | nc -U /var/lib/haproxy/stats | cut -d "," -f 1,2,5-11,18,24,27,30,36,50,37,56,57,62 | column -s, -t                                                        Thu Mar 30 15:01:19 2017

# pxname          svname              scur  smax  slim  stot   bin        bout     dreq  status    lastchg  pid  throttle  rate_max  check_status  cli_abrt  lastsess  last_chk               ttime
somedb            FRONTEND            1     1     512   1      0          0        0     OPEN               1              1
appp01            coolappss-01        1     1           1      0          0              no check           1              1                       0         2973                             0
coredb            BACKEND             1     1     52    1      0          0        0     UP        2975     1              1                       0         2973                             0

Now the columns are lined up and any only columns I am interested in are being shown.

If you want to know what the column numbers are for this cut command will help.

echo "show stat" | nc -U /var/lib/haproxy/stats | grep "#" | tr ',' '\n' | nl
Share:
39,456

Related videos on Youtube

nelaaro
Author by

nelaaro

Linux admin, tech enthusiast. opensource evangelist.

Updated on September 18, 2022

Comments

  • nelaaro
    nelaaro over 1 year

    In the examples, I have seen on the net

    https://www.datadoghq.com/blog/how-to-collect-haproxy-metrics/#show-me-the-metrics

    You can use the command line

    echo "show stat" | nc -U /var/lib/haproxy/stats  
    

    Which is very ugly in the output. Columns don't match and it is difficult to see what is going on.

    # 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,comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime,
    someapp,FRONTEND,,,1,1,512,1,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,1,,,,,,,,,,,0,0,0,,,0,0,0,0,,,,,,,,
    anotherdb,anotherdb-tp-01,0,0,1,1,,1,0,0,,0,,0,0,0,0,no check,1,1,0,,,,,,1,2,1,,1,,2,0,,1,,,,,,,,,,0,,,,0,0,,,,,3006,,,0,0,0,0,
    someotherappdb,BACKEND,0,0,1,1,52,1,0,0,0,0,,0,0,0,0,UP,1,1,0,,0,3008,0,,1,2,0,,1,,1,0,,1,,,,,,,,,,,,,,0,0,0,0,0,0,3006,,,0,0,0,0,
    

    Is there a good way to clean this up and make it more readable.

  • w00t
    w00t almost 6 years
    +1 for column, which I've forgotten exists.
  • cherouvim
    cherouvim over 4 years
    For systems where /var/lib/haproxy/stats does not exist, another way is to do: echo "show stat" | sudo socat stdio /run/haproxy/admin.sock
  • Bruce
    Bruce about 4 years
    If you want filtered output and the header row, it's easy to achieve with awk echo "show stat" | sudo socat stdio /var/run/admin.sock | cut -d ',' -f 1,2,18 | awk 'NR==1 {print}; /somedb/ {print}' | column -s, -t.