标签:lvs
编写脚本
zabbix没有权限执行ipvsadm命令,并且没有登录终端shell,解决方案:
visudo zabbix ALL=NOPASSWD: /sbin/ipvsadm 注释掉: #Defaults requiretty
[root@lvs-backup zabbix_agentd.conf.d]# ls /etc/zabbix/scripts/lvs_discovery_InActConn.sh /etc/zabbix/scripts/lvs_discovery_InActConn.sh [root@lvs-backup 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配置文件
[root@lvs-backup zabbix_agentd.conf.d]# ls /etc/zabbix/zabbix_agentd.conf.d/lvs_InActConn.conf /etc/zabbix/zabbix_agentd.conf.d/lvs_InActConn.conf [root@lvs-backup 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"
[root@lvs-backup 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"}]} [root@lvs-backup scripts]#
3.创建模板以及加入自动发现规则
创建模板
将获取的值制作成图像
博文链接:
http://bbs.chinaunix.net/thread-4069054-1-1.html
http://nginxs.blog.51cto.com/4676810/1423224
本文出自 “Linux革命” 博客,请务必保留此出处http://kaibinyuan.blog.51cto.com/7304008/1711863
标签:lvs
原文地址:http://kaibinyuan.blog.51cto.com/7304008/1711863