nagios监控linux网卡流量(check_traffic.sh)
admin
2023-02-09 06:40:09
0

1、安装所需组件

   yum install perl perl-devel perl-CPAN bc net-snmpd net-snmp-utils -y

   perl -MCPAN -eshell  & cpan> install Bundle::LWP

   编译安装nrpe(参考教程:http://2860664.blog.51cto.com/2850664/1559056


以下是被监控端设置

2、下载check_traffic.s脚本

   下载地址:https://codeload.github.com/cloved/check_traffic/zip/v1.3.11

   解压文件后,上传check_traffic.sh到/usr/local/nagios/libexec

   chmod +x check_traffic.sh

   chown nagios.nagcmd check_traffic.sh

3、设置snmp参数

   vi /etc/snmp/snmpd.conf

com2sec notConfigUser  被监控端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.25.1.1
access  notConfigGroup ""      any       noauth    exact  all none none
view all    included  .1                               80
syslocation Unknown (edit /etc/snmp/snmpd.conf)
syscontact Root  (configure /etc/snmp/snmp.local.conf)

service snmpd start

chkconfig snmpd on

4、在被监控端测试脚本

   cd /usr/local/nagios/libexec

   ./check_traffic.sh -V 2c -C public -H 192.168.1.247 -I 2 -w 1200,1500 -c 1700,1800 -K -B

OK - The Traffic In is 0.72KB, Out is 0.60KB, Total is 1.32KB. The Check Interval is 43s |In=0.72KB;1200;1700;0;0 Out=0.60KB;1500;1800;0;0 Total=1.32KB;2700;3500;0;0 Interval=43s;1200;1800;0;0

   其中红色为被监控端的IP地址。

4、vi /usr/local/nagios/etc/nrpe.cfg  添加

command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 192.168.1.247 -I 2 -w 1200,1500 -c 1700,1800 -K -B

   

以下是nagios主机的设置

5、服务器端测试

 

/usr/local/nagios/libexec/check_nrpe -H 192.168.1.247 -c check_traffic

OK - The Traffic In is 0.48KB, Out is 0.11KB, Total is 0.59KB. The Check Interval is 28s |In=0.48KB;1200;1700;0;0 Out=0.11KB;1500;1800;0;0 Total=0.59KB;2700;3500;0;0 Interval=28s;1200;1800;0;0


vi /usr/local/nagios/etc/nagios.cfg  添加

   cfg_file=/usr/local/nagios/etc/objects/nginx.cfg

6、touch /usr/local/nagios/etc/objects/nginx.cfg

   vi /usr/local/nagios/etc/objects/nginx.cfg  (注意修改被监控端的IP)内容如下  

****************************************我是分割线************************************   

define host{
           use             linux-server
          host_name     nginx
          alias         nginx
          address       被监控端IP
        }
define service{
        use                      generic-service
        host_name             nginx
        service_description     check-swap
        check_command        check_nrpe!check_swap
               }
define service{
        use                      generic-service
        host_name             nginx
        service_description     check-load
       check_command         check_nrpe!check_load
               }
define service{
        use                      generic-service
        host_name             nginx
       service_description     check-disk
       check_command        check_nrpe!check_sda1
               }
define service{
        use                      generic-service
        host_name             nginx
       service_description     check-users
       check_command        check_nrpe!check_users
               }
define service{
        use                    generic-service
        host_name           nginx
        service_description  otal_procs
        check_command     check_nrpe!check_total_procs
}
define service{
        use                             generic-service         ; Name of service template to use
        host_name                       nginx
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }
define service{
    use                     generic-service
    host_name               nginx
    service_description     nginx_status
    check_command           check_nrpe!check_nginx!
        notifications_enabled           0
        }
define service{
    use                     generic-service
    host_name               nginx
    service_description     network_traffic
    check_command           check_nrpe!check_traffic!
        notifications_enabled           0
}

****************************************我也是分割线************************************

报错信息

7、nagios服务器报错

Unknown - Read or Write File /var/tmp/check_traffic_192.168.1.247_2__itnms.hist_dat_64 Error with user uid=501(nagios) gid=503(nagcmd) groups=502(nagios),503(nagcmd).

解决方法:chmod nagios.nagcmd /var/tmp/check_traffic_192.168.1.247_2__itnms.hist_dat_64


相关内容

热门资讯

王虹、邓煜为啥能获菲尔兹奖? 当地时间7月23日早晨,2026年国际数学家大会在美国费城开幕。国际数学联盟在开幕式上正式公布第二十...
高温津贴,不能用绿豆汤冲抵 近日,深圳市人力资源和社会保障局发布关于高温津贴的典型劳动仲裁案例,并普法提醒:即便劳动合同约定日薪...
菲律宾,你到底想干什么 中国和菲律宾关系,又出幺蛾子了。反正,最近几天,麻烦不断,场面火爆。仁爱礁,菲两艘小艇冲撞我巡逻船只...
聚焦长期价值,方舟云康以数智化... 来源:江南时报 在慢病管理领域,单纯追逐“流量”的互联网医疗模式已显疲态。当线上获客成本持续走高、用...
阿拉比卡以后喝不到了?对话云大... 搜狐科技《思想大爆炸——对话科学家》栏目第157期,对话云南大学农学院教授何飞飞。 嘉宾简介: 何飞...
微信重磅更新!超实用 7月23日,微信派发文晒微信未成年人模式,进入“未成年人模式”后,家长可为孩子设置“每日消费限额”和...
13岁少年帮聋哑舅舅卖瓜,记者... 河南13岁少年帮聋哑舅舅卖瓜走红,记者购买2万斤西瓜助农,临走时少年妈妈拉着记者表示感谢:“如果不是...
12999元起!三星首款阔折叠... 7月22日晚,三星举行 Galaxy Z8 系列折叠屏手机全球发布会,一口气带来了Galaxy Z ...
西门子抽油烟机为什么不转了 西门子抽油烟机为什么不转了1、可能是油烟机里面的电机坏掉了,或者是里面的风扇叶片上有太多的油渍,也有...
四预警齐发!台风“红霞”最新路... 今天(24日)6时,中央气象台发布高温黄色预警、暴雨蓝色预警、强对流天气蓝色预警、台风橙色预警。高温...