近两天 在整合公司的监控  要不zabbix上 逐步迁移到 nagios+ganglia平台上

在网络监控这块发现ganglia获取的信息不能自定义为Mb(也可能我没有找对配置位置)

从网上 搜索发现 有网友编写了 traffic.sh的脚本,我就拿来用了j_0057.gif

traffic.sh 下载地址 http://pan.baidu.com/s/1o8PoDBG

进入正题

客户端  

1.安装snmp组件

[root@localhost ~]# yum install -y  net-snmp   net-snmp-libs net-snmp-utils

2.更改配置文件 /etc/snmp/snmpd.conf

com2sec notConfigUser   default      public #改为 监控主机ip

access  notConfigGroup ""      any       noauth    exact  systemview  none none # 改为mib2

#view mib2   included  .iso.org.dod.internet.mgmt.mib-2 fc # 去除注释

3.测试连接 

snmpwalk -v 2c -c public 127.0.0.1 #需要将配置文件ip临时改为127.0.0.1  正确的话会出现好多内容


服务端

1. 移动check_traffic.sh脚本到 nagios插件目录,本例位于 /usr/lib64/nagios/plugins/

mv check_traffic.sh  /usr/lib64/nagios/plugins/

2.更改脚本权限 

chmod 755 check_traffic.sh

3.安装 bc  #报错信息见error 1

[root@m plugins]# yum install -y bc.x86_64

4.

查看网卡编号

[root@m plugins]# /usr/lib64/nagios/plugins/check_traffic.sh -V 2c -C public -H 10.10.4.41 -L

测试 

/usr/lib64/nagios/plugins/check_traffic.sh -V 2c -C public -H 10.10.4.41 -I 2 -w 300,500 -c 600,800 -M -b           # -I 2的2为检测到的网卡索引号

OK - The Traffic In is 33.38Mbps, Out is 15.28Mbps, Total is 48.66Mbps. The Check Interval is 90s |In=33.38Mbps;300;600;0;0 Out=15.28Mbps;500;800;0;0 Total=48.66Mbps;800;1400;0;0 Interval=90s;1200;1800;0;0

5.添加命令

vim /etc/nagios/objects/commands.cfg 

# 'check_traffic' command definition

define command{

      command_name   check_traffic

      command_line   $USER1$/check_traffic.sh -V 2c -C public -H  $HOSTNAME$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -M -B

}

vim /etc/nagios/objects/api.cfg #本例是在现有的基础上添加的 


define service{

        use                     api-service

         hostgroup_name              api

        service_description     check_traffic

        notifications_enabled   1

        check_command           check_traffic!2!300,300!600,600

        max_check_attempts      1

}



error 1

[root@m plugins]# /usr/lib64/nagios/plugins/check_traffic.sh -V 2c -C public -H 10.10.4.41 -I 2 -w300,500 -c600,800 -M -b

/usr/lib64/nagios/plugins/check_traffic.sh: line 449: bc: command not found

/usr/lib64/nagios/plugins/check_traffic.sh: line 454: bc: command not found

/usr/lib64/nagios/plugins/check_traffic.sh: line 457: bc: command not found

/usr/lib64/nagios/plugins/check_traffic.sh: line 458: bc: command not found

/usr/lib64/nagios/plugins/check_traffic.sh: line 461: [: too many arguments

/usr/lib64/nagios/plugins/check_traffic.sh: line 576: bc: command not found

/usr/lib64/nagios/plugins/check_traffic.sh: line 577: bc: command not found

解决方法

yum install -y bc 

error 2

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

 Unknown是由于

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

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


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


在此感谢,两位大神

http://blog.csdn.net/liansehai/article/details/15499767  恋涩海

http://bingdian.blog.51cto.com/94171/167614/