Linux · 2015年2月12日 0

nagios监控TCP连接数

cd /usr/local/nagios/libexec
编写插件
vim check_ip_cons.sh
#!/bin/bash
#tcp connet
if [ $# != 2 ];then
echo "Usage:$0 -w num1 -c num2"
exit
fi
ip_conns=`netstat -n |grep ESTABLISHED|wc -l`
if [ $ip_conns -lt $1 ];then
echo "OK -connet counts is $ip_conns"
exit 0
fi
if [ $ip_conns -ge $1 -a $ip_conns -lt $2 ];then
echo "Warning -connet counts is $ip_conns"
exit 1
fi
if [ $ip_conns -ge $2 ];then
echo "Critical -connet counts is $ip_conns"
exit 2
fi

chmod +x check_ip_cons.sh
chown nagios.nagios check_ip_cons.sh
vim ../etc/nrpe.cfg(添加以下文字)
command[check_TCP]=/usr/local/nagios/libexec/check_ip_cons.sh 1000 2000
注:超过1000是Warning超过2000是Critical(依个人情况设定。)
在nagios监控上编辑被监控机模板添加以下信息

#TCP连接数
define service{
use local-service
host_name wangdl-vm-006.chinacloudapp.cn
service_description 当前TCP连接数
check_command check_nrpe!check_TCP
}

保存退出
service nagios reload
去nagios的页面刷新就能看到新的监控项了。
注:本文参考此链接http://yingzi234.blog.51cto.com/3374280/1213310(感谢各位开源精神的朋友)