tongy 发表于 2015-11-23 09:22:16

Nagios监控网络流量

  之前用过一款监控网络流量的插件,感觉不太好用。因为他的in和out值只能限制到一个值。下面新用一个插件in和out值能够分别定义。和以前的插件方法大概相同。
  
  1. nagios主机安装net-snmp和RRDTOOL
  2. 参照cacti,windows和linux的监控。在被监控主机上添加nagios主机IP
  
  1.   查找以下字段
  #       sec.namesource          community
  com2sec local   127.0.0.1       public
  com2sec local    192.168.2.2    public
  #将"comunity"字段改为你要设置的密码.比如"public".将“default”改为你想哪台机器可以看到你的snmp信息,如192.168.2.2,我这里将source修改成了nagios主机。
  2.   查找以下字段
  #context sec.model sec.level matchread   writenotif
  access MyROGroup ""      any       noauth    exactall    none   none
  access MyRWGroup ""      any       noauth    exactall    all    none
  #将read字段修改成all
  3.   查找以下字段
  #         incl/excl subtree                        mask
  view all    included.1                               80
  #把view前的#去掉
  
  3. 测试
  重启 snmp
  service snmpd restart
  在被空端:
  snmpwalk –c public –v 2c localhost
  在主控端测试
  snmpwalk -v 2c -c public被控端ip |grep IF
  如果没有if信息不能获取流量
  3. 获取被控端网卡信息
  
  # ./check_traffic.sh -V 2c -C public -H 192.168.2.6 -L
  List Interface for host 192.168.2.6.
  Interface index 1 orresponding tolo
  Interface index 2 orresponding toeth0
  Interface index 3 orresponding toeth1
  
  4. 在nagios主机上添加check_traffic脚本
  
  # ./check_traffic.sh -h
  Usage:
  ./check_traffic.sh [ -v ] [ -6 ] [ -r ] -V 1|2c|3 -C snmp-community -H host [ -L ] -I interface -w in,out-warning-value-c in,out-critical-value -K/M -B/b
  Example:
  ./check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 4 -w 200,100 -c 300,200 -K -B
  Or -r to use Range Value Options:
  ./check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 4 -r -w 200-300,100-200 -c 100-400,50-250 -K -B
  If you don't use -K/M -B/b options, default -K -b, corresponding to Kbps. (默认单位)
  Make sure that the check interval greater than 5 Seconds.
  Or modify the Min_Interval var in this file Line 180.
  And, if you want in Verbose mode, use -v, to check the debug messages in the file /tmp/check_traffic.$$.
  Or use ./check_traffic.sh [ -v ] -V 1|2c|3 -C snmp-community -H host -L
  To list all interfaces on specify host.
  
  # ./check_traffic.sh -V 2c -C public -H 192.168.2.6 -I 3 -w 200,300 -c 400,500 -K –B 定义in和out值分别超过200K、300K警告,超过400K,500k严重警告。
  OK - It's the first time for this plugins run. We'll get the data from the next time.
  第一次执行,history data file(/var/tmp/check_traffic_${Host}_${Interface}.hist_dat)不存在,因此会由此提示,可以忽略,再执行一次可以正正常获取
  OK - The Traffic In is 1.3750KB, Out is 0.0KB, Total is 1.3750KB. The Check Interval is 104s |In=1.3750KB;200;400;0;0 Out=0.0KB;300;500;0;0 Total=1.3750KB;500;900;0;0 Interval=104s;1200;1800;0;0
  
  5. 在nagios的command文件里面定义check_traffic命令
  
  # 'check_traffic' command definition
  define command{
  command_namecheck_traffic
  command_line $USER1$/check_traffic.sh -V 2c -Cpublic -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -K -B监控单位可以自定义
  }
  
  6. 在nagios的监控对象cfg文件里面添加check_traffic
  
  define service{
  use             generic-service
  host_name       linux
  service_description   traffic
  check_command            check_traffic!3!200,300!400,500 监控eth1网卡
  }             #与定义的宏对应添加参数值
  
页: [1]
查看完整版本: Nagios监控网络流量