采用curl来获取数据,只监控了rate、rate_max、Sessions Cur、Sessions Max、error和端口状态。脚本如下,:
#!/bin/bash stat_file=`curl -s 'http://192.168.1.252:8888/stats;csv;' -H 'Authorization: Basic YWRtaW46YWRtaW4=' | grep -E "web|http-in"` #Session rate rate() { echo "$stat_file" | awk -F ',' '/'$1'/{print $34}' } rate_max() { echo "$stat_file" | awk -F ',' '/'$1'/{print $36}' } #Sessions scur() { echo "$stat_file" | awk -F ',' '{if($2~/'$1'/) print $5}' } smax() { echo "$stat_file" | awk -F ',' '{if($2~/'$1'/) print $6}' } stot() { echo "$stat_file" | awk -F ',' '{if($2~/'$1'/) print $8}' } #err ereq() { echo "$stat_file" | awk -F ',' '{if($2~/'$1'/) print $13}' } econ() { echo "$stat_file" | awk -F ',' '{if($2~/'$1'/) print $14}' } #services stats stats() { echo "$stat_file" | awk -F ',' '{if($2~/'$1'/) print $37}' } $1 $2
修改zabbix_agentd.conf,添加key值:
UserParameter=haproxy.frontend.rate,/opt/web/zabbix/scripts/check_haproxy.sh rate FRONTEND UserParameter=haproxy.frontend.rate_max,/opt/web/zabbix/scripts/check_haproxy.sh rate_max FRONTEND UserParameter=haproxy.frontend.smax,/opt/web/zabbix/scripts/check_haproxy.sh smax FRONTEND UserParameter=haproxy.web249.rate,/opt/web/zabbix/scripts/check_haproxy.sh rate web249 UserParameter=haproxy.web249.scur,/opt/web/zabbix/scripts/check_haproxy.sh scur web249 UserParameter=haproxy.web249.smax,/opt/web/zabbix/scripts/check_haproxy.sh smax web249 UserParameter=haproxy.web249.stot,/opt/web/zabbix/scripts/check_haproxy.sh stot web249 UserParameter=haproxy.web249.econ,/opt/web/zabbix/scripts/check_haproxy.sh econ web249 UserParameter=haproxy.web249.ereq,/opt/web/zabbix/scripts/check_haproxy.sh ereq web249 UserParameter=haproxy.web249.stats,/opt/web/zabbix/scripts/check_haproxy.sh stats web249 UserParameter=haproxy.web250.rate,/opt/web/zabbix/scripts/check_haproxy.sh rate web250 UserParameter=haproxy.web250.scur,/opt/web/zabbix/scripts/check_haproxy.sh scur web250 UserParameter=haproxy.web250.smax,/opt/web/zabbix/scripts/check_haproxy.sh smax web250 UserParameter=haproxy.web250.stot,/opt/web/zabbix/scripts/check_haproxy.sh stot web250 UserParameter=haproxy.web250.econ,/opt/web/zabbix/scripts/check_haproxy.sh econ web250 UserParameter=haproxy.web250.ereq,/opt/web/zabbix/scripts/check_haproxy.sh ereq web250 UserParameter=haproxy.web250.stats,/opt/web/zabbix/scripts/check_haproxy.sh stats web250 UserParameter=haproxy.web254.rate,/opt/web/zabbix/scripts/check_haproxy.sh rate web254 UserParameter=haproxy.web254.scur,/opt/web/zabbix/scripts/check_haproxy.sh scur web254 UserParameter=haproxy.web254.smax,/opt/web/zabbix/scripts/check_haproxy.sh smax web254 UserParameter=haproxy.web254.stot,/opt/web/zabbix/scripts/check_haproxy.sh stot web254 UserParameter=haproxy.web254.econ,/opt/web/zabbix/scripts/check_haproxy.sh econ web254 UserParameter=haproxy.web254.ereq,/opt/web/zabbix/scripts/check_haproxy.sh ereq web254 UserParameter=haproxy.web254.stats,/opt/web/zabbix/scripts/check_haproxy.sh stats web254
重启zabbix_agentd,登陆zabbix管理页面即可添加item和图像,如图:
转载于:https://blog.51cto.com/hellolinux/1379987