Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> 電腦軟件教程 >> 服務器技術 >> 服務器綜合 >> 監控Windows服務器CPU利用率使用Nagios

監控Windows服務器CPU利用率使用Nagios

日期:2017/1/23 16:29:46      編輯:服務器綜合

監控WIndows服務器相關性能,建議采用SNMP方式,但是配置比較麻煩。假如采用NSCLIENT++插件會更加方便,前提是需要在具體被監控服務器上安裝插件。萬一影響了服務器本身的應用程序就不太好了。所以,我一直在尋找監控Windows服務器的SNMP方式。

1、增加腳本如下:

cat /usr/lib/nagios/plugins/check_snmp_win_cpuload.pl
#!/usr/bin/perl
#
# syntax: check_win_snmp_cpuload.pl HOST COMMUNITY WARN CRIT
#
# returns average load % across all CPUs
#

use strict;
use Net::SNMP;

my $host = shift;
my $community = shift;
my $warn = shift;
my $crit = shift;

unless($crit) {
errorExit("syntax: check_win_snmp_cpu.pl HOST COMMUNITY WARN CRIT");
}

our %ERRORS = (
OK => 0,
WARNING => 1,
CRITICAL => 2,
UNKNOWN => 3,
DEPENDENT => 4
);

my $oidCpuTable='.1.3.6.1.2.1.25.3.3.1.2';

# get SNMP session object
my ($snmp, $err) = Net::SNMP->session(
-hostname => $host,
-community => $community,
-port => 161,
-version => 1
);
errorExit( $err ) unless (defined($snmp));

# get cpu load table
my $response = $snmp->get_table(
-baseoid => $oidCpuTable
);
errorExit( "error getting cpu table" ) unless $response;
my %value = %{$response};
$snmp->close();

my $cnt = 0;
my $sum = 0;
foreach my $load ( values %value ){
$cnt += 1;
$sum += $load;
};
my $pct = int ($sum / $cnt);

my $err = ($pct > $crit) ? 'CRITICAL' : ($pct > $warn) ? 'WARNING' : 'OK';
print "$err : CPU Load $pct%\n";
exit $ERRORS{$err};

sub errorExit {
my $msg = shift;
print "UNKNOWN: $msg\n";
exit $ERRORS{UNKNOWN};
}


2、定義相應的執行命令:

cat mysnmp.cfg
define command{
command_name snmp_win_cpu
command_line /usr/lib/nagios/plugins/check_snmp_win_cpuload.pl '$HOS
TADDRESS$' public 80 90
}


3、新建服務配置文件:

cat service.cfg
define service {
host_name jw-inside
service_description CPU
check_command snmp_win_cpu
use generic-service
}

4、新建主機文件:
define host {
host_name jw-inside
alias jw-inside
address 10.10.10.11
use generic-host
icon_image vendors/windowsxp.png
icon_image_alt jw-inside-server
vrml_image vendors/windowsxp.png
statusmap_image vendors/windowsxp.png
}

Copyright © Windows教程網 All Rights Reserved