顯示頁面舊版反向連結Fold/unfold all回到頁頂 本頁是唯讀的,您可以看到原始碼,但不能更動它。您如果覺得它不應被鎖上,請詢問管理員。 ====== HAProxy 納入 Zabbix 監控 ====== * Prerequisites * Zabbix Server >= 2.x * Zabbix Frontend >= 2.x * HAProxy >= 1.3 * Socat ===== @HAProxy Server 安裝程序 ===== * 新增 userparameter_haproxy.conf <code sh> vi /etc/zabbix/zabbix_agentd.d/userparameter_haproxy.conf</code><file> # # Discovery Rule # # HAProxy Frontend, Backend and Server Discovery rules UserParameter=haproxy.list.discovery[*],/usr/local/bin/haproxy_discovery.sh $1 $2 # Frontend / Backend current sessions UserParameter=haproxy.stat.bin[*],echo "show stat" | socat $1 stdio | grep "^$2,$3" | cut -d, -f9 UserParameter=haproxy.stat.bout[*],echo "show stat" | socat $1 stdio | grep "^$2,$3" | cut -d, -f10 UserParameter=haproxy.stat.scur[*],echo "show stat" | socat $1 stdio | grep "^$2,$3" | cut -d, -f5 UserParameter=haproxy.stat.status[*],echo "show stat" | socat $1 stdio | grep "^$2,$3" | cut -d, -f18 | cut -d\ -f1 </file> * 新增 haproxy_discovery.sh <code sh> vi /usr/local/bin/haproxy_discovery.sh</code><file> #!/bin/bash # # Get list of Frontends and Backends from HAPROXY # Example: ./haproxy_discovery.sh [/var/run/haproxy/info.sock] FRONTEND|BACKEND|SERVERS # First argument is optional and should be used to set location of your HAPROXY socket # Second argument is should be either FRONTEND, BACKEND or SERVERS, will default to FRONTEND if not set # # !! Make sure the user running this script has Read/Write permissions to that socket !! # ## haproxy.cfg snippet # global # stats socket /run/haproxy/info.sock mode 666 level user #HAPROXY_SOCK="/var/run/haproxy/info.sock" HAPROXY_SOCK="/var/lib/haproxy/stats" [ -n "$1" ] && echo $1 | grep -q ^/ && HAPROXY_SOCK="$(echo $1 | tr -d '\040\011\012\015')" get_stats() { echo "show stat" | socat ${HAPROXY_SOCK} stdio 2>/dev/null | grep -v "^#" } [ -n "$2" ] && shift 1 case $1 in B*) END="BACKEND" ;; F*) END="FRONTEND" ;; S*) for backend in $(get_stats | grep BACKEND | cut -d, -f1 | uniq); do for server in $(get_stats | grep "${backend}" | grep -v BACKEND | cut -d, -f2); do serverlist="$serverlist,"'{"{#BACKEND_NAME}":"'$backend'","{#SERVER_NAME}":"'$server'"}' done done echo '{"data":['${serverlist#,}']}' exit 0 ;; *) END="FRONTEND" ;; esac for frontend in $(get_stats | grep "$END" | cut -d, -f1 | uniq); do felist="$felist,"'{"{#'${END}'_NAME}":"'$frontend'"}' done echo '{"data":['${felist#,}']}' </file><code sh> chmod a+x /usr/local/bin/haproxy_discovery.sh </code> * /usr/local/bin/haproxy_discovery.sh 依據實際狀況更改了原本 info.sock 定義 * /var/run/haproxy/info.sock -> /var/lib/haproxy/stats * 重起 zabbix-agent <code sh> service zabbix-agent restart</code> * 測試<code sh>sudo zabbix_agentd -t haproxy.list.discovery[BACKEND] </code><file> haproxy.list.discovery[BACKEND] [t|{"data":[{"{#BACKEND_NAME}":"stats-back"},{"{#BACKEND_NAME}":"pxc-back"},{"{#BACKEND_NAME}":"pxc-onenode-back"}]}] </file> ===== @Zabbix Server 設定程序 ===== * 至 https://github.com/anapsix/zabbix-haproxy/ 下載 [[https://raw.githubusercontent.com/anapsix/zabbix-haproxy/master/haproxy_zbx_template.xml|haproxy_zbx_template.xml]] * 將 haproxy_zbx_template.xml 匯入至 Zabbix Server → Configuration → Templates → Import ===== 參考網址 ===== * http://blog.random.io/haproxy/ {{tag>haproxy zabbox}} tech/zabbix/haproxy.txt 上一次變更: 2015/05/25 19:35由 jonathan