大概步骤如下:

1、安装snmpd服务软件包并设置启动之。

2、上传监控插件至被监控机nagios/libexec目录并授权

3、网卡参数检测

4、 nrpe.cfg文件增加监控command

5、 nagios服务器配置service.cfg添加监控项

 【客户端】

1、首先安装net-snmp的软件包 和rrdtool

yum -y install net-snmp*

2、修改snmpd.conf文件

第41行 修改为 com2sec notConfigUser  localhost       public

第62行修改为:access  notConfigGroup ""      any       noauth    exact  mib2 none none

第89行view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc 前面的注释去掉

启动snmpd服务

 3、上传插件并且授权

上传check_traffic.sh至/usr/local/nagios/libexec,插件在下面附近有下载

chown nagios.nagios ./check_traffic.sh

4、网卡参数检测

/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -L

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

看看想要监控的是哪一块网卡,如果是eth0,则参数为2

5、测试是否可以正常采集数据

/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

 注:

-V snmp协议版本

-C 共同体名

-I 参数对应上面-L输出的网卡index值。标示监视相应的网卡

 正确返回结果:

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

】在客户端的snmp配置文件和nrpe文件中的 -H后面的Ip应该写客户端本身的,而不应该是服务器的Ip,因为nagios是通过nrpe来获取数据,并不是通过snmp来获取的即前者snmp数据只会在本机产生,自己采集自身数据而后由nrpe插件传输到nagios服务器前端显示出来(数据文件在本机)。

更改/var/tmp/check_traffic* 文件权限为nagios用户可读写。简单的给个777吧。

chmod 777 /var/tmp/check_traffic_127.0.0.1_2.hist_dat_root__32

重启nrpe

【nagios服务端】

1、定义services.cfg

 define service{

        host_name               xx --客户端

        service_description     traffic

        check_command           check_nrpe!check_traffic!3!300,400!500,600

        max_check_attempts      5

        normal_check_interval   5

        retry_check_interval    2

        check_period            24x7

        notification_interval   10

        notification_period     24x7

        notification_options    w,u,c,r

        contact_groups          shyygroup

        }

重启nagios,然后再服务器端手工测试

root># ./check_nrpe -H xx -c check_traffic

OK - The Traffic In is 1.25KB, Out is 3.37KB, Total is 4.62KB. The Check Interval is 298s |In=1.25KB;300;500;0;0 Out=3.37KB;400;600;0;0 Total=4.62KB;700;1100;0;0 Interval=298s;1200;1800;0;0

##错误

在运行check_traffic.sh脚本的时候,会出现:

./check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 1 -w 1200,1500 -c 1700,1800 -K -b

./check_traffic.sh: line 449: bc: command not found

./check_traffic.sh: line 454: bc: command not found

./check_traffic.sh: line 457: bc: command not found

./check_traffic.sh: line 458: bc: command not found

./check_traffic.sh: line 461: [: too many arguments

./check_traffic.sh: line 576: bc: command not found

./check_traffic.sh: line 577: bc: command not found

Unknown - Can not found data in the history data file. Please to check the file /var/tmp/check_traffic_127.0.0.1_3.hist_dat_root__64 ,or use use verbose mode and check the debug file

--解决:

 bc: command not found

yum search bc,结果出现一大堆,然后发现有这么一个需要安装

bc.x86_64 0:1.06.95-1.el6

果断执行yum -y install bc

 至于另外一个错误:

 Unknown是由于

第一次执行,因为history data file不存在,因此会由此提示,可以忽略。

如果每次执行都忽略,则要检查/var/tmp下是否有/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件生成。

文件的内容是系统当前的时间,in及out当前的数值。

###

http://bbs.linuxtone.org/thread-6345-1-1.html

--没有用到snmp,直接用Perl脚本写的