- 编写脚本
zabbix没有权限执行ipvsadm命令,并且没有登录终端shell,解决方案:
visudo zabbix ALL=NOPASSWD: /sbin/ipvsadm 注释掉: #Defaults requiretty
[[email protected] zabbix_agentd.conf.d]# ls /etc/zabbix/scripts/lvs_discovery_InActConn.sh /etc/zabbix/scripts/lvs_discovery_InActConn.sh [[email protected] zabbix_agentd.conf.d]# cat lvs_ActConn.conf # monitor lvs status UserParameter=lvs.status.discovery,/etc/zabbix/scripts/lvs_discovery_ActConn.sh UserParameter=lvs.status[*],sudo /sbin/ipvsadm -L -n | egrep -v ‘TCP|UDP|Virtual|LocalAddress|ActiveConn‘ | grep "$1" | awk ‘$$5 > 0 {print $$5}‘
#zabbix Server端获取数据 zabbix_get -s 10.6.6.32 -k lvs.InActive.status.discovery { "data":[ {"{#IFNAME}":"10.*.*.*:8080"}, {"{#IFNAME}":"10.*.*.*:8080"}, {"{#IFNAME}":"10.*.*.*:8080"}, {"{#IFNAME}":"10.*.*.*:8080"}, {"{#IFNAME}":"10.*.*.*:8080"}]}
2.编写zabbix配置文件
[[email protected] zabbix_agentd.conf.d]# ls /etc/zabbix/zabbix_agentd.conf.d/lvs_InActConn.conf /etc/zabbix/zabbix_agentd.conf.d/lvs_InActConn.conf [[email protected] zabbix_agentd.conf.d]# cat /etc/zabbix/scripts/lvs_discovery_ActConn.sh #!/bin/bash #filename: lvs_discovery.sh #author: YuanBinbin MY_KEY=(`sudo /sbin/ipvsadm -L -n |egrep -v ‘TCP|UDP|Virtual|LocalAddress|ActiveConn‘ |grep "$1"|awk ‘$5 > 0 {print $2}‘`) length=${#MY_KEY[@]} printf "{\n" printf ‘\t‘"\"data\":[" for ((i=0;i<$length;i++)) do printf ‘\n\t\t{‘ printf "\"{#IFNAME}\":\"${MY_KEY[$i]}\"}" if [ $i -lt $[$length-1] ];then printf ‘,‘ fi done printf "]}\n"
[[email protected] scripts]# ./lvs_discovery_ActConn.sh { "data":[ {"{#IFNAME}":"10.*.9.*:8080"}, {"{#IFNAME}":"10.*.9.*:8080"}, {"{#IFNAME}":"10.*.9.*:8080"}, {"{#IFNAME}":"10.*.9.*:8080"}, {"{#IFNAME}":"10.*.9.*:8080"}]} [[email protected] scripts]#
3.创建模板以及加入自动发现规则
创建模板
将获取的值制作成图像
博文链接:
http://bbs.chinaunix.net/thread-4069054-1-1.html
http://nginxs.blog.51cto.com/4676810/1423224
时间: 2024-11-01 13:50:51