温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nagios监控Linux、Windows的网卡流量

发布时间:2020-07-17 17:08:46 来源:网络 阅读:686 作者:chenshengang 栏目:移动开发

总有人问通过nagios怎么监控网络流量,这里就分享一下:


使用/usr/local/nagios/libexec/中的check_traffic.sh,不但可以监控Linux的网卡流量,也可以监控Windows服务器的流量,此脚本check_traffic.sh来源于网络,如果你的nagios里没有它就下载附件上传,并修改权限即可。


监控脚本 check_traffic.sh,上传至Nagios服务器 /usr/local/nagios/libexec/ 目录里

修改权限:

chown nagios.nagios  check_traffic.sh

chmod 755  check_traffic.sh


1、Check_traffic.sh的用法

[root@oracle libexec]#/usr/local/nagios/libexec/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


We can use -r to use Range Value Options:


Example:


./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.  列出主机所有网络接口信息,这个可以知道网卡的index值


2、以IP:192.168.0.2的Windows 2008系统为例子:


获取值的默认单位是Kbps。


然后通过/usr/local/nagios/libexec/check_traffic.sh -V 2c -C   public  -H 192.168.0.2 -L


去确认自己要监控对象的网卡代号


List Interface for host 192.168.0.2.

Interface index 1 orresponding to  MS TCP Loopback interface

Interface index 2 orresponding to  Citrix PV Ethernet Adapt


输出信息中index后面的数字就是你要监控网卡的代号


可以自己通过命令先执行一下:


#/usr/local/nagios/libexec/check_traffic.sh -V 2c -C  public  -H 192.168.0.2 -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

#/usr/local/nagios/libexec/check_traffic.sh -V 2c -C  public  -H 172.22.8.12 -I 65540  -w 10,10 -c 30,30 -M


输出:

Critical - The Traffic In is 2.01Mbps, Out is 36.19Mbps, Total is 38.20Mbps. The Check Interval is 106s |In=2.01Mbps;10;30;0;0 Out=36.19Mbps;10;30;0;0 Total=38.20Mbps;20;60;0;0 Interval=106s;1200;1800;0;0


#/usr/local/nagios/libexec/check_traffic.sh -V 2c -C  public  -H 172.22.8.12 -I 65540  -w 100,100 -c 300,300 -M

输出:

OK - The Traffic In is 2.05Mbps, Out is 37.00Mbps, Total is 39.05Mbps. The Check Interval is 114s |In=2.05Mbps;100;300;0;0 Out=37.00Mbps;100;300;0;0 Total=39.05Mbps;200;600;0;0 Interval=114s;1200;1800;0;0


V 代表snmp版本


C 代表community的名称


H 代表主机IP


I  代表网卡号


w 、c 代表的是×××警告、红色报警   10,10  30,30(代表in,out)



一切OK后就能看到以下监控信息图:

Nagios监控Linux、Windows的网卡流量

注意:


如果以非nagios用户身份,手动测试执行过该脚本,请在正式使用该脚本前,删除/var/tmp下对应测试生成的/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件,否则会造成nagios用户无法读写该文件的错误。


还有出现以下提示的意思是:


OK - It's the first time for this plugins run. We'll get the data from the next time

意思是说,OK,没问题, - 这个插件是第一次为此运行。从下一次开始我们将得到相关的数据


The check interval must greater than 30 Seconds. But now it's 20. Please retry it later.

检查间隔必须大于30秒。但现在是20秒。请稍后重试。


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI