bjghzly 发表于 2019-1-14 14:19:48

Nagios網卡流量監控報錯check_traffic.sh

        操作很简单。首先将check_triffic.sh脚本拷贝到/usr/local/nagios/libexec/里面。然后在/usr/local/nagios/etc/objects/commands.cfg文件中添加
  

[*]  #######################################################################
[*]  #
[*]  #                            check_traffic
[*]  #
[*]  #######################################################################
[*]  define command{
[*]        command_name check_traffic
[*]        command_line $USER1$/check_traffic.sh -V 2c -C public -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$,$ARG3$ -c $ARG4$,$ARG5$   -K -B
[*]        }
  当然这是我的command文件内容。大家可以参照网上的自行定义。但要注意单位。
  默认是Kbps,我這里改成了慣用的KB。
  然后通过/usr/local/nagios/libexec/check_traffic.sh -V 2c -Czhuzhu -H 192.168.0.202 -L
  去确认自己要监控对象的网卡代号(index號)
  List Interface for host 192.168.0.202.
Interface index 1 orresponding toMS TCP Loopback interface
Interface index 2 orresponding toCitrix PV Ethernet Adapt
  输出信息中index后面的数字就是你要监控网卡的代号
  可以自己通过命令先执行一下:
  /usr/local/nagios/libexec/check_traffic.sh -V 2c -C zhuzhu -H 192.168.0.202 -I 2-w 10,10 -c 30,30
  输出:
  OK - The Traffic In is 4Kbps, Out is 0.0Kbps, Total is 4Kbps. The Check Interval is 127s |In=4Kbps;10;30;0;0 Out=0.0Kbps;10;30;0;0 Total=4Kbps;20;60;0;0 Interval=127s;1200;1800;0;0
  
  V 代表snmp版本
  C 代表community的名称
  H 代表主机IP
  I代表网卡号
  w 、c就不必说了吧
  补充:10,1030,30(代表in,out)
  
   现在编辑services.cfg
  define service{
         host_name               192.168.0.202
         service_description   traffic
         check_command         check_traffic!2!10!10!30!30
         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          wingroup
         }
  
  然后重启nagios服务就应该齐活了。但是其实不然,我在监控公司文件服务器时(流量比较猛)。报了诸如下告警:
  SERVICE ALERT: 192.168.0.202;traffic;UNKNOWN;SOFT;1;Maybe 32 bit counter overflow, because we got a negative value here.
  SERVICE ALERT: 192.168.0.202;;traffic;UNKNOWN;SOFT;3;Unknown - Read or Write File /var/tmp/check_traffic_192.168.0.202;_11.hist_dat_root__32 Error with user uid=517(nagios) gid=517(nagios) groups=517(nagios)
  后来Google到了解决的方法如下:
  如果以非nagios用户身份,手动测试执行过该脚本,请在正式使用该脚本前,删除/var/tmp下对应测试生成的/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件,否则会造成nagios用户无法读写该文件的错误。
  可以直接全部清空该目录,等下次网卡流量检查后会对应每台主机重新生成一次。

  最后就能看到以下信息:
  http://blog.运维网.com/attachment/201306/141913726.png
http://blog.运维网.com/attachment/201306/142028568.png
  




页: [1]
查看完整版本: Nagios網卡流量監控報錯check_traffic.sh