当前位置: > Linux服务器 > 监控工具 >

zabbix 监控 haproxy

时间:2015-01-17 02:12来源:chinaunix.net 作者:chinaunix.net
一、下载安装socat
[root@haproxy-01 ~]# cd /usr/local/src
[root@haproxy-01 ~]# wget http://www.dest-unreach.org/socat/download/socat-1.7.1.3.tar.gz
[root@haproxy-01 ~]# tar xzf socat-1.7.1.3.tar.gz
[root@haproxy-01 ~]# cd socat-1.7.1.3/
[root@haproxy-01 ~]# ./configure
[root@haproxy-01 ~]# make
[root@haproxy-01 ~]# make install


二、使用方法
[root@haproxy-01 ~]# echo "help" | socat /etc/haproxy/haproxy.sock stdio
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

[root@haproxy-01 ~]# echo "show stat" | /usr/bin/sudo /usr/local/bin/socat /etc/haproxy/haproxy.sock stdio
#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,
http-in,FRONTEND,,,3,55,2000,1386359,1686146049,15519347480,0,0,28336,,,,,OPEN,,,,,,,,,2,1,0,,,,0,13,0,93,,,,0,1046786,297984,38697,2199,690,,13,94,1386359,,,
web_pool,web-nginx13,0,0,3,45,,1358023,1685267221,15513457636,,0,,0,1794,0,0,no check,1,1,0,,,,,,2,2,1,,1358023,,2,13,,93,,,,1,1046786,297984,9590,56,0,0,,,,2327,2,
web_pool,BACKEND,0,0,3,49,0,1358023,1685267221,15513457636,0,0,,0,2250,0,0,UP,1,1,0,,0,137722,0,,2,2,0,,1358023,,1,13,,93,,,,0,1046786,297984,10361,2199,690,,,,,2327,2,
haproxy_stats,FRONTEND,,,0,4,2000,3396,1551872,28555167,0,0,61,,,,,OPEN,,,,,,,,,2,3,0,,,,0,0,0,4,,,,0,2410,0,63,923,0,,0,3,3396,,,
haproxy_stats,BACKEND,0,0,0,1,2000,923,1551872,28555167,0,0,,923,0,0,0,UP,0,0,0,,0,137722,0,,2,3,0,,0,,1,0,,1,,,,0,0,0,0,923,0,,,,,0,0,


三、建产key
vim /etc/zabbix/zabbix_agentd.conf

取数据。

http-in.scur
[root@haproxy-01 ~]# echo "show stat" | /usr/bin/sudo /usr/local/bin/socat /etc/haproxy/haproxy.sock stdio | awk -F, '/http-in,FRONTEND/{print $5}'

http-in.slimit
[root@haproxy-01 ~]# echo "show stat" | /usr/bin/sudo /usr/local/bin/socat /etc/haproxy/haproxy.sock stdio | awk -F, '/http-in,FRONTEND/{print $7}'

http-in.rate
[root@haproxy-01 ~]# echo "show stat" | /usr/bin/sudo /usr/local/bin/socat /etc/haproxy/haproxy.sock stdio | awk -F, '/http-in,FRONTEND/{print $34}'

web-nginx13.qcur
[root@haproxy-01 ~]# echo "show stat" | /usr/bin/sudo /usr/local/bin/socat /etc/haproxy/haproxy.sock stdio | awk -F, '/web_pool,web-nginx13/{print $3}' 

web-nginx13.econ
[root@haproxy-01 ~]# echo "show stat" | /usr/bin/sudo /usr/local/bin/socat /etc/haproxy/haproxy.sock stdio | awk -F, '/web_pool,web-nginx13/{print $14}' 


创建key
UserParameter=haproxy.http-in.scur, /bin/echo "show stat" | /usr/bin/sudo /usr/local/bin/socat /etc/haproxy/haproxy.sock stdio | awk -F, '/http-in,FRONTEND/{print $5}'
UserParameter=haproxy.http-in.slimit, /bin/echo "show stat" | /usr/bin/sudo /usr/local/bin/socat /etc/haproxy/haproxy.sock stdio | awk -F, '/http-in,FRONTEND/{print $7}'
UserParameter=haproxy.web-nginx13.qcur, /bin/echo "show stat" | /usr/bin/sudo /usr/local/bin/socat /etc/haproxy/haproxy.sock stdio | awk -F, '/web_pool,web-nginx13/{print $3}' 
UserParameter=haproxy.web-nginx13.econ, /bin/echo "show stat" | /usr/bin/sudo /usr/local/bin/socat /etc/haproxy/haproxy.sock stdio | awk -F, '/web_pool,web-nginx13/{print $14}' 


四、 修改sudo
visudo
注释
#Defaults    requiretty
加入
zabbix ALL=(ALL) NOPASSWD:/usr/local/bin/socat


五、出图。
想要哪个字段自己取出来就行了。




参考:http://mattiasgeniar.be/2010/10/22/advanced-monitoring-haproxy-with-zabbix-agent/ (责任编辑:IT)
------分隔线----------------------------