1. 程式人生 > >haproxy 基本維護命令和監控統計命令

haproxy 基本維護命令和監控統計命令

1服務管理命令
使用rpm包安裝,伺服器管理指令碼安裝在/etc/rc.d/init.d/haproxy,用法如下。
haproxy {start|stop|restart|reload|condrestart|status|check}


1.2配置檔案檢查
1、使用服務管理指令碼檢查
#/etc/rc.d/init.d/haproxy check


注:只能檢查當前使用的配置檔案。


2、使用命令檢查
#haproxy –c –f


2監控統計
2.1監控統計頁面
在配置檔案裡面配置了統計頁面,可以通過瀏覽器訪問。
修改/etc/haproxy/haproxy.cfg,增加下面幾行:
listen admin_stats
bind 0.0.0.0:1080
mode http
log 127.0.0.1 local0 err
stats uri/admin?stats
#/etc/init.d/haproxy restart
重啟服務,然後通過http://ip地址:1080/admin?stats訪問或者在配置檔案/etc/haproxy/haproxy.cfg全域性設定中加入如下幾行
stats uri /haproxy-stats
stats realm haproxy\ statistics
stats auth admin:pasSWord
#/etc/init.d/haproxy restart
重啟服務,然後通過http://ip地址/haproxy-stats訪問,輸入使用者名稱和密碼進入檢視。


2.2監控統計指令碼
原始碼包中包含一個stats_haproxy.sh指令碼,通過呼叫socat訪問統計介面採集資料,功能等同於統計頁面。命令用法如下。
Usage : stats_haproxy.sh [options] -s section
--section -s section : section to use ( --list format)
Options :
--socket -S [socket] : socket to use (default: /var/run/haproxy.stat)
--list -l : print available sections
--help -h : print this message


命令示例如下。
#./stats_haproxy.sh –s public
命令輸出如下:
50 sessions/s (avg: 50 ) 93 concurrent sessions
53 sessions/s (avg: 51 ) 92 concurrent sessions
34 sessions/s (avg: 45 ) 95 concurrent sessions
33 sessions/s (avg: 42 ) 92 concurrent sessions
33 sessions/s (avg: 40 ) 101 concurrent sessions


2.3監控統計命令
使用socat命令,可以直接通過命令列採集資料。命令示例如下。
#echo "help" | socat /var/run/haproxy.stat stdio
命令輸出如下,列出了可用的命令引數,其中引數stat可以顯示統計資訊。
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
show errors : report last request and response errors for each proxy
show sess [id] : report the list of current sessions or dump this session
get weight : report a server's current weight
set weight : change a server's weight
set timeout : change a timeout setting
disable server : set a server in maintenance mode
enable server : re-enable a server that was previously in maintenance mode


#echo "show stat" | socat /var/run/haproxy.stat stdio
命令輸出為csv格式,如下。示例指令碼就是格式化
#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,
mm,FRONTEND,,,0,4,30000,124,51741,1426307,0,0,10,,,,,OPEN,,,,,,,,,1,1,0,,,,0,0,0,10,,,,0,111,0,13,0,0,,0,10,124,,,
mm,test,0,0,0,4,,114,51441,1424624,,0,,0,0,0,0,no check,1,1,0,,,,,,1,1,1,,114,,2,0,,10,,,,0,111,0,3,0,0,0,,,,13,0,
mm,BACKEND,0,0,0,4,30000,114,51741,1426307,0,0,,0,0,0,0,UP,1,1,0,,0,13450,0,,1,1,0,,114,,1,0,,10,,,,0,111,0,3,0,0,,,,,13,0,


2.4 第三方工具hatop
1、源站:http://feurix.org/projects/hatop/
目前最新版本是hatop-0.7.7.tar.gz
2、安裝
進入解壓後的原始碼包目錄,執行下面命令安裝。
#install -m 755 bin/hatop /usr/local/bin
#install -m 644 man/hatop.1 /usr/local/share/man/man1
#gzip /usr/local/share/man/man1/hatop.1


3、hatop使用
Hatop介面類似top,分為5個子介面(切換分別按 1 2 3 4 5或tab鍵選擇)。
注:按5進入CLI模式,返回其它介面,只能按tab鍵切換。
hatop介面示例如下,輸出資訊與web統計介面類似,相關引數含義檢視官方文件
http://feurix.org/projects/hatop/readme/
#hatop -s /var/run/haproxy.stat


轉載於https://segmentfault.com/a/1190000003023634#articleHeader17