为了了解被监控服务器的TCP连接情况,因为没有现成的监控插件,所以根据网上的资料,自行编写一个插件以满足需要
,现将使用方法分享给大家。
进入nagios插件的目录
$ cd /usr/local/nagios/libexec/
$ vi check_tcp_num
#!/bin/sh
tcp_num=`netstat -an|awk '/ESTABLISHED/{print $5}'|wc -l`
if [ $tcp_num -lt $1 ];then
echo "TCP_NUM OK - TCP connection number for $tcp_num|ESTABLISHED=$tcp_num"
exit 0
elif [ $tcp_num -ge $1 -a $tcp_num -lt $2 ];then
echo "TCP_NUM WARNING - TCP connection number for $tcp_num|ESTABLISHED=$tcp_num"
exit 1
else
echo "TCP_NUM CRITICAL - TCP connection number for $tcp_num|ESTABLISHED=$tcp_num"
exit 2
fi
$ chmod 755 check_tcp_num
添加监控命令
$ echo "command[check_tcp_num]=/usr/local/nagios/libexec/check_tcp_num 500 800" >> /usr/local/nagios/etc/nrpe.cfg
重启nrpe即可
监控主机上添加相应的命令即可获取监控信息
阅读(2083) | 评论(0) | 转发(0) |