nagios 配置 check_traffic 流量监控模块(Server 端)

  1. 安装软件包
    yum -y install net-snmp*
    chkconfig nrpe on
    chkconfig snmpd on
    chkconfig nagios on
  2. 修改snmp参数,vi /etc/snmp/snmpd.conf(可备份snmpd.conf,修改下面的localhost-IP为服务器IP,保存此文件即可)
    com2sec notConfigUser 127.0.0.1 public 
    com2sec notConfigUser localhost-IP public 
    
    group notConfigGroup v1 notConfigUser 
    group notConfigGroup v2c notConfigUser 
    
    view systemview included .1.3.6.1.2.1.1 
    view systemview included .1.3.6.1.2.1.2 
    view systemview included .1.3.6.1.2.1.25.1.1 
    view all included .1 
    
    access notConfigGroup "" any noauth exact all none none 
    snmpd.conf Code
  3. 拷贝check_traffic.sh到/usr/lib64/nagios/plugins/check_traffic.sh
    check_traffic.sh文件GitHub下载地址:https://github.com/cloved/check_traffic/blob/master/check_traffic.sh
    wget https://github.com/cloved/check_traffic/archive/master.zip

  4. 赋予执行权限并测试:
    chmod +x check_traffic.sh
    ./check_traffic.sh -V 2c -C public -H your_ip -I 2 -w 1200,1500 -c 1700,1800 -K -B
    ./check_traffic.sh -V 2c -C public -H your_ip -L
    ./check_traffic.sh -V 2c -C public -H 127.0.0.1 -L

  5. 例子:
    ./check_traffic.sh -V 2c -C public -H your_ip -N eth0 -w 8,7 -c 16,14 -M -b
    -V snmp 版本
    -C 认证信息
    -H 主机IP
    -N 网卡
    -w 8,7   下行/上行流量超过 8,7 Mbit/s 警告
    -c 16,14 下行/上行流量超过 16,14 Mbit/s 严重
    -M 兆
    -b 比特

  6. 编辑/etc/nagios/objects/command.cfg文件,追加:

    # 'check_traffic' command definition
    define command{
            command_name    check_traffic
            command_line    $USER1$/check_traffic.sh -V 2c -C public -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$ -c $ARG3$ -M -b
            }
    Check _traffic Code
  7. 编辑/etc/nagios/objects/localhost.cfg文件

    define service{
            use                             local-service         ; Name of service template to use
            host_name                       localhost
            service_description             Check_Trafffic
            check_command                   check_traffic!2!12,15!20,30
            notifications_enabled           1
            normal_check_interval           5
            retry_interval          1
            }
    localhost.cfg

    并且修改localhost.cfg文件中的IP地址(127.0.0.1)为本机的IP!!!!!!!(坑了我2天)

  8. 删除临时文件
    /var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件
  9. 重启nagios服务,配置成功后的截图如下


  10. 参考下面链接的部分内容:
    http://2860664.blog.51cto.com/2850664/1567068

posted @ 2015-06-11 21:18  Mr黄瑞  阅读(943)  评论(0编辑  收藏  举报