Monitor the CPU usage of Windows servers using Nagios (SNMP Mode)

Source: Internet
Author: User

We recommend that you use SNMP to monitor the performance of WIndows servers, but the configuration is cumbersome. It would be more convenient to use NSCLIENT ++ plug-in, provided that the plug-in needs to be installed on a specific monitored server. In case the application affects the server itself, it is not good. Therefore, I have been searching for the SNMP method for monitoring Windows servers.

1. Add the following script:

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 % every SS 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 = & gt; 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. Define the corresponding execution command:

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. Create a service configuration file:

Cat service. cfg
Define service {
Host_name jw-inside
Service_description CPU
Check_command snmp_win_cpu
Use generic-service
}

4. Create a host file:
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
}

In fact, the person familiar with nagios configuration only needs the script in step 1. I will not film

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.