linux haproxy 脚本,zabbix监控haproxy状态-shell脚本

采用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和图像,如图:

6c0c4b1fc4829227207859db9089de13.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值