|
【客户端】
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 前面的注释去掉
3、启动snmpd服务
#service snmpd restart
4、上传插件并且授权
1)上传check_traffic.sh至/usr/local/nagios/libexec
2)#chown nagios.nagios check_traffic.sh
#chmod +x check_traffic.sh
5、网卡参数检测
#/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
6、测试是否可以正常采集数据
#/usr/local/nagios/libexec/check_traffic.sh -V 2c -C zhezi -H 127.0.0.1 -I 2 -w 1,50 -c 180,200 -M –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服务器前端显示出来(数据文件在本机)。
6、修改nagios客户端的配置文件
#vim /usr/local/nagios/etc/nrpe.cfg
增加如下内容
command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C zhezi -H 127.0.0.1 -I 2 -w 1,50 -c 180,200 -M –b
注:-w和-c后面的两个值,一个是IN流量值,一个是out流量值
7、删除缓存文件
#cd /var/tmp/
#rm -rf *
8、重启nrpe
#ps -ef |grep nrpe
root 9227 25212 0 16:18 pts/0 00:00:00 grep nrpe
test 29963 1 0 15:45 ? 00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
#kill 29963
#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
【服务端】
1、修改主机配置文件
#vim /usr/local/nagios/etc/objects/1.1.1.1.cfg
在最后面增加如下内容
define service{
use local-service ; Name of service template to use
host_name 1.1.1.1 //IP地址
service_description liuliang //服务名称
check_command check_nrpe!check_traffic
notifications_enabled 1
}
2、校验配置文件是否正确
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
有如下提示,说明配置文件正确
Total Warnings: 0
Total Errors: 0
3、重启nagios服务端
#service nagios restart
常见问题解决方法:
# ./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当前的数值。
|
|