系统版本
[root@localhost libexec]# cat /etc/redhat-release
CentOS release 5.6 (Final)
1 安装和配置snmp
1)yum install net-snmp-utils net-snmp net-snmp-libs -y
2)vi /etc/snmp/snmpd.conf
把下面两行的#号去掉
#view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
#view all included .1 80
把下面的语句
access notConfigGroup "" any noauth exact systemview none none
改为:
access notConfigGroup "" any noauth exact mib2 none none
3) 启动snmp
/etc/init.d/snmpd start
2 下载监控流量脚本测试
wget https://raw.githubusercontent.com/cloved/check_traffic/master/check_traffic.sh --no-check-certificate ##放到/usr/local/nagios/libexec目录下
chmod +x /usr/local/nagios/libexec/check_traffic.sh
获取网卡信息
[root@localhost libexec]# ./check_traffic.sh -V 2c -C public -H localhost -L
List Interface for host localhost.
Interface index 1 orresponding to lo
Interface index 2 orresponding to eth0
[root@localhost libexec]# ./check_traffic.sh -V 2c -C public -H localhost -I 2 -w 1000,1200 -c 1400,1500 -K -B ## -I 后面的2 由上面的命令获取
OK - The Traffic In is 0.11KB, Out is 1.08KB, Total is 1.19KB. The Check Interval is 1526s |In=0.11KB;1000;1400;0;0 Out=1.08KB;1200;1500;0;0 Total=1.19KB;2200;2900;0;0 Interval=1526s;1200;1800;0;0
定义in和out值分别超过1000K、1200K警告,超过1400K,1500k严重。(第一次运行没有输出,30s后再运行就有输出)
3 在被监控端定义check_traffic命令
vi /usr/local/nagios/etc/nrpe.cfg
添加
command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 2 -w 1000,1200 -c 1400,1500 -K -B
4 在监控端定义服务
vi ../etc/objects/services.cfg
define service{
use generic-service
host_name localhost
service_description traffic
check_command check_nrpe!check_traffic
}
5 重启服务
pkill nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
/etc/init.d/nagios reload
6 手动测试
[root@localhost libexec]# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_traffic