1,zabbix客户端配置
zabbix_agentd.conf末尾添加如下配置
### LVSConn
UserParameter=LVSAll,/usr/local/zabbix/etc/lvs_connstatus.sh LVSAll
UserParameter=LVSConn,/usr/local/zabbix/etc/lvs_connstatus.sh LVSConn
UserParameter=LVSInConn,/usr/local/zabbix/etc/lvs_connstatus.sh LVSInConn
2,lvs连接数脚本如下
cat lvs_connstatus.sh
#!/bin/bash function LVSConn { sudo /sbin/ipvsadm -L -n | sed -n ‘2,$p‘ |awk ‘{print $5}‘|awk ‘BEGIN{sum=0}{sum+=$1}END{print sum}‘ } function LVSInConn { sudo /sbin/ipvsadm -L -n | sed -n ‘2,$p‘ |awk ‘{print $6}‘| awk ‘BEGIN{sum=0}{sum+=$1}END{print sum}‘ } function LVSAll { sudo /sbin/ipvsadm -L -n | sed -n ‘2,$p‘ |awk ‘{print $5 + $6}‘ |awk ‘BEGIN{sum=0}{sum+=$1}END{print sum}‘ } # Run the requested function $1
3,设置sudo权限
echo ‘Defaults:zabbix !requiretty‘ >>/etc/sudoers
echo ‘zabbix ALL=(ALL) NOPASSWD:/sbin/ipvsadm‘ >>/etc/sudoers
4,zabbix web界面添加lvs监控模板,添加lvs客户端监控项 ,lvs监控模板如下
5,监控效果如下
时间: 2025-01-16 18:41:23