天天看點

Nagios監控Windows的網卡流量

Nagios監控Windows的網卡流量

使用/usr/local/nagios/libexec/中的check_traffic.sh,不但可以監控Linux的網卡流量,也可以監控Windows伺服器的流量。

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:

./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.

2 Windows用戶端的設定

在此例中使用windows 2008舉例,IP為192.168.19.142。

2.1 安裝SNMP服務 

Windows 2008中是通過添加feature來添加snmp服務的,詳細過程請檢視附件文檔。 

而Windows2003是在控制台-添加删除程式-添加删除元件-Management and Monitoring Tools中安裝snmp服務的。

2.2 配置SNMP服務

使用services.msc啟動服務控制台,設定snmp community的traps和security,如下:(詳細配置請檢視附件文檔)

然後重新開機snmp服務,可以使用cmdànetstat –an | find “161”驗證snmp服務啟動情況

3 Nagios伺服器的設定

3.1 安裝net-snmp的相關元件

         # yum install –y net-snmp*

3.2 編輯command.cfg檔案

vi /usr/local/nagios/etc/object/command.cfg添加如下内容:

define command{

      command_name    check_bandwidth

      command_line    $USER1$/check_traffic.sh -V 2c -C snmp-community -H $HOSTADDRESS$ -I $ARG1$ -w $ARG2$,$ARG3$ -c $ARG4$,$ARG5$

        }

注:-C後參數為在伺服器上設定的community值;

-I 為大寫的i,為網卡接口的index值

-w與-c後的兩個參數分别為in/out的流量門檻值

3.3 編輯windows.cfg主機配置檔案

首先使用如下的指令檢視被監控的windows主機的網卡資訊:

/usr/local/nagios/libexec/check_traffic.sh -V 2c -C snmp-community -H IPADD -L

然後會列出被監控機的網卡資訊,檢視需要監控的網卡,記錄其index值即可。

如上例中所示中指令為:

/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public1 -H 192.168.19.142 –L如下圖所示:(圖檔在附件文檔中)

vi windows.cfg添加如下内容:

define service{

        use                     generic-service

        host_name               winserver

        service_description        Traffic

        check_command          check_bandwidth!10!200000!300000!400000!500000

此處的10為網卡資訊的index值,此值通過如上的指令檢視:

繼續閱讀