總有人問(wèn)通過(guò)nagios怎么監(jiān)控網(wǎng)絡(luò)流量,這里就分享一下:
創(chuàng)新互聯(lián)建站主營(yíng)千山網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,重慶APP軟件開(kāi)發(fā),千山h5小程序制作搭建,千山網(wǎng)站營(yíng)銷推廣歡迎千山等地區(qū)企業(yè)咨詢
使用/usr/local/nagios/libexec/中的check_traffic.sh,不但可以監(jiān)控Linux的網(wǎng)卡流量,也可以監(jiān)控Windows服務(wù)器的流量,此腳本check_traffic.sh來(lái)源于網(wǎng)絡(luò),如果你的nagios里沒(méi)有它就下載附件上傳,并修改權(quán)限即可。
監(jiān)控腳本 check_traffic.sh,上傳至Nagios服務(wù)器 /usr/local/nagios/libexec/ 目錄里
修改權(quán)限:
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. 列出主機(jī)所有網(wǎng)絡(luò)接口信息,這個(gè)可以知道網(wǎng)卡的index值
2、以IP:192.168.0.2的Windows 2008系統(tǒng)為例子:
獲取值的默認(rèn)單位是Kbps。
然后通過(guò)/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 192.168.0.2 -L
去確認(rèn)自己要監(jiān)控對(duì)象的網(wǎng)卡代號(hào)
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后面的數(shù)字就是你要監(jiān)控網(wǎng)卡的代號(hào)
可以自己通過(guò)命令先執(zhí)行一下:
#/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 代表主機(jī)IP
I 代表網(wǎng)卡號(hào)
w 、c 代表的是×××警告、紅色報(bào)警 10,10 30,30(代表in,out)
一切OK后就能看到以下監(jiān)控信息圖:
注意:
如果以非nagios用戶身份,手動(dòng)測(cè)試執(zhí)行過(guò)該腳本,請(qǐng)?jiān)谡绞褂迷撃_本前,刪除/var/tmp下對(duì)應(yīng)測(cè)試生成的/var/tmp/check_traffic_${Host}_${Interface}.hist_dat文件,否則會(huì)造成nagios用戶無(wú)法讀寫(xiě)該文件的錯(cuò)誤。
還有出現(xiàn)以下提示的意思是:
OK - It's the first time for this plugins run. We'll get the data from the next time
意思是說(shuō),OK,沒(méi)問(wèn)題, - 這個(gè)插件是第一次為此運(yùn)行。從下一次開(kāi)始我們將得到相關(guān)的數(shù)據(jù)
The check interval must greater than 30 Seconds. But now it's 20. Please retry it later.
檢查間隔必須大于30秒。但現(xiàn)在是20秒。請(qǐng)稍后重試。