Monitor Windows server CPU utilization using Nagios

  
        

Monitoring the performance of the WIndows server. It is recommended to use the SNMP method, but the configuration is cumbersome. It would be more convenient to use the NSCLIENT++ plugin, provided that the plugin needs to be installed on the specific monitored server. In the unlikely event that the application that affects the server itself is not good. So, I have been looking for SNMP ways to monitor Windows servers.

1, add the script as follows:

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 objectmy ($snmp, $err) = Net::SNMP->session(-hostname => $host,-community => $community,-port => 161,-version => 1); errorExit( $err ) unless (defined($snmp));

# get cpu load tablemy $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, define the corresponding execution command :

cat mysnmp.cfgdefine command{command_name snmp_win_cpucommand_line /usr/lib/nagios/plugins/check_snmp_win_cpuload.pl '$HOSTADDRESS$' public 80 90}

3, New Service Profile: < Br>

cat service.cfgdefine service {host_name jw-insideservice_description CPUcheck_command snmp_win_cpuuse generic-service}

4, create a new host file: define host {host_name jw-insidealias jw-insideaddress 10.10.10.11use generic-hosticon_image Vendors/windowsxp.pngicon_image_alt jw-inside-servervrml_image vendors/windowsxp.pngstatusmap_image vendors/windowsxp.png }

Copyright © Windows knowledge All Rights Reserved