在haproxy的global里添加
stats socket /var/run/haproxy.sock mode 666 level user
打开haproxy的socket监控
以下为监控的脚本
#!/bin/bash [ $1 = 'http_server' ] && WEBGROUP=$1,FRONTEND || WEBGROUP=$1,BACKEND case "$2" in "comp" ) IN=`/bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $52}'` OUT=`/bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $53}'` echo "scale=4;($IN-$OUT)/$IN*100" | bc ;; "qcur" ) /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $3}' ;; "qmax" ) /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $4}' ;; "scur") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $5}' ;; "smax") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $6}' ;; "slim") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $7}' ;; "stot") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $8}' ;; "bin") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $9}' ;; "bout") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $10}' ;; "dreq") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $11}' ;; "dresp") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $12}' ;; "ereq") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $13}' ;; "econ") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $14}' ;; "eresp") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $15}' ;; "eretr") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $16}' ;; "eredis") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $17}' ;; "status") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $18}' ;; "weight") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $19}' ;; "act") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $20}' ;; "bck") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $21}' ;; "chkfail") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $22}' ;; "chkdown") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $23}' ;; "lastchg") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $24}' ;; "downtime") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $24}' ;; "qlimit") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $26}' ;; "pid") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $27}' ;; "iid") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $28}' ;; "sid") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $29}' ;; "throttle") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $30}' ;; "lbtot") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $31}' ;; "tracked") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $32}' ;; "tpye") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $33}' ;; "rate") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $34}' ;; "rate_lim") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $35}' ;; "rate_max") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $36}' ;; "check_status") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $37}' ;; "check_code") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $38}' ;; "check_duration") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $39}' ;; "hrsp_1xx") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $40}' ;; "hrsp_2xx") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $41}' ;; "hrsp_3xx") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $42}' ;; "hrsp_4xx") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $43}' ;; "hrsp_5xx") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $44}' ;; "hrsp_other") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $45}' ;; "hanafail") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $46}' ;; "req_rate") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $47}' ;; "req_rate_max") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $48}' ;; "req_tot") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $49}' ;; "cli_abrt") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $50}' ;; "srv_abrt") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $51}' ;; "comp_in") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $52}' ;; "comp_out") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $53}' ;; "comp_byp") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $54}' ;; "comp_rsp") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $55}' ;; "lastsess") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $56}' ;; "last_chk") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $57}' ;; "last_agt") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $58}' ;; "qtime") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $59}' ;; "ctime") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $60}' ;; "rtime") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $61}' ;; "ttime") /bin/echo "show stat"|/usr/sbin/socat /var/run/haproxy.sock stdio|awk -v n=$WEBGROUP -F, '$0~n{print $62}' ;; *) /bin/echo 'error' ;; esac
haproxy的一些指标
pxname 组名
svname 服务器名
qcur 当前队列
qmax 最大队列
scur当前会话用户
smax最大会话用户
slim会话限制
stot会话总量
bin入口流量
bout出口流量
dreq拒绝的请求
dresp拒绝的响应
ereq错误请求
econ错误链接
eresp错误响应
wretr警告重试次数
wredis
status服务器状态
weight权重
act是否活动Y/N
bck备用
chkfail检查宕机0
chkdown检查宕机0
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_bypbypass大小
comp_rsp
lastsess
last_chk
last_agt
qtime
ctime
rtime
ttime