使用Nagios监控Windows服务器CPU利用率(SNMP方式)
监控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%
";
exit $ERRORS{$err};
sub errorExit {
my $msg = shift;
print "UNKNOWN: $msg
";
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
}
其实熟悉nagios配置的人,只需要步骤1中的脚本就可以。我就不上图片了
相关新闻>>
- 发表评论
-
- 最新评论 更多>>