如何使用套接字在命令行上查看 haproxy 状态

如何使用套接字在命令行上查看 haproxy 状态

在这些例子中,我在网上看到过

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

您可以使用命令行

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

输出结果非常丑陋。列不匹配,很难看清发生了什么。

# 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,

有没有好的方法可以清理它并使其更具可读性。

答案1

我发现以下内容很有用

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'

它将产生如下输出

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

现在各列已排列好,并且仅显示我感兴趣的列。

如果您想知道列号是多少,这个剪切命令会有所帮助。

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

相关内容