一、操作被监控机
1、安装SNMP服务
[root@nagios nagios]# yum -y install net-snmp*
2、修改/etc/snmp/snmpd.conf
# sec.name source community
com2sec notConfigUser 127.0.0.1 public //IP地址设为监控机的IP
# group context sec.model sec.level prefix read write notif
access notConfigGroup "" any noauth exact mib2 none none //改systemview为mib2
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc //去掉前面的"#"注释符
3、启动SNMP服务
[root@nagios nagios]#service snmpd start
4、测试SNMP服务
[root@nagios nagios]#snmpwalk -v 2c -c public 127.0.0.1 //如果出现一大串东西就可以了
5、开启端口
如果设置了防火墙,就将UDP协议的161端口号打开
二、操作监控机
1、上传check_traffic.sh插件
如果之前装过nagios,就直接上传check_traffic.sh到/usr/local/nagios/libexec/
2、授权插件
[root@nagios nagios]#chown nagios.nagios /usr/local/nagios/libexec/check_traffic.sh
3、网卡参数检测,选择要监控的网卡索引号
[root@nagios nagios]# /usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -L //IP地址为被监控机的IP
List Interface for host 127.0.0.1.
Interface index 1 orresponding to lo
Interface index 2 orresponding to eth0
Interface index 3 orresponding to eth1
4、测试是否能够正常采集到数据
[root@nagios nagios]#/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 2 -w 1200,1500 -c 1700,1800 -K -b
OK - The Traffic In is 356Kbps, Out is 414Kbps, Total is 770Kbps. The Check Interval is 30s |In=356Kbps;1200;1700;0;0 Out=414Kbps;1500;1800;0;0 Total=770Kbps;2700;3500;0;0 Interval=30s;1200;1800;0;0
注:-I 2的2为检测到的网卡索引号
5、将命令写入监测端的 commands.cfg 中
define command{
command_name check_traffic
command_line $USER1$/check_traffic.sh -V 2c -C public -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -K -B}
6、编辑localhost.cfg增加监控网卡流量项目
define service{
use local-service
host_name localhost
service_description traffic
check_command check_traffic!2!4000,5000!6000,7000
}
7.重启nagios
[root@nagios nagios]#service nagios restart