Nagios 监控网络流量(Windows主机和交换机)

本文所使用的监控流量脚本为“石头”写的check_traffic脚本

脚本下载地址:http://pan.baidu.com/share/link?shareid=1817509007&uk=2737059485

在Nagios服务端和被监控Windows主机均安装SNMP

1、安装与配置snmp

  请查看:http://www.cnblogs.com/wowchky/p/3227323.html              

2、上传监控插件并授权

1) 将下载下来的check_traffic.sh上传至被监控主机的/usr/local/nagios/libexec目录下。

2) 更改属主为nagios并修改文件权限

  chown nagios:nagios check_traffic.sh 

  chmod 755 check_traffic.sh 

3) 检测网卡

  /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

4) 测试是否可以正常采集数据

  /usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 2 -w 300,350 -c 500,600 -K -B

返回:

  OK - The Traffic In is 27.12KB, Out is 1.12KB, Total is 28.24KB. The Check Interval is 32s |In=27.12KB;300;500;0;0 Out=1.12KB;350;600;0;0 Total=28.24KB;650;1100;0;0 Interval=32s;1200;1800;0;0

注:-V为snmp的版本,-C为团体名,-I参数对应上面-L输出的Interface index的值,标识监控的网卡,-w与-c后的两个参数分别为in/out的流量阈值,如需了解该插件的其它用法可以使用-h来获取帮助。即/usr/local/nagios/libexec/check_traffic.sh -h

5) 更改/var/tmp/check_traffic* 文件权限为nagios用户可读写,直接给该文件为777。

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

3、在被监控端添加check_traffic命令

define command{
  command_name    check_traffic
  command_line      $USER1$/check_traffic.sh -V 2c -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -K -B
  }

注:-w 300,350 -c 500,600可根据实际情况修改之

4、在Nagios监控服务器端添加check_traffic服务

1) 编辑service.cfg添加监控网卡流量项目(注意要先添加相应的主机)

define service {

  host_name                    windows

  service_description          check traffic

  check_command               check_traffic

  max_check_attempts            5

  normal_check_interval          3

  retry_check_interval            2

  check_period                  24x7

  notification_interval            10

  notification_period             24x7

  notification_options            w,u,c,r

        contact_groups                WindowsGroups

}

2) 检查nagios.cfg配置文件并重启nagios

  /usr/local/nagios/bin/nagios  -v /usr/local/nagios/etc/nagios.cfg

  /etc/ini.d/nagios restart

 

原文地址:https://www.cnblogs.com/wowchky/p/3111839.html