System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Nagios graph for CPU utilisation

SOLVED
Go to solution
chindi
Respected Contributor

Nagios graph for CPU utilisation

Hi, Am trying to configure nagios graphs for cpu utilisation , but when am trying below .pl file am getting only %usr calculation , as a result of which my main aim of using Nagios is gone for toss.

It must actually show usr+sys .

 

#!/usr/bin/perl

#**************************************************************
#Plugin Nagios chequear uso CPU
# Configurar el en nrpe de hp-ux
# Integracion en nrpe, en la seccion del archivo nrpe.cfg, "The following examples use hardcoded command arguments...", incluir la linea:
# command[check_hpux_cpu]=/opt/nrpe/libexec/check_hpux_cpu.pl -w 80 -c 90
# Realizador: Jaime Andres Cardona
# Correo: ja_an_ca@hotmail.com
# Version: 1.0
# Fecha: 2011-Oct-26

use Getopt::Long;
&Getopt::Long::config('auto_abbrev');

my $numbarg = @ARGV;
($numbarg < 2) && &show_help;

my %STATUSCODE = ( 'UNKNOWN' => '-1',
'OK' => '0',
'WARNING' => '1',
'CRITICAL' => '2');


sub show_help {
printf("usage: ./check_hpux_cpu.pl -w # -c #\n
options:
-w warning threshold (%)
-c critical threshold (%)

");
exit($STATUSCODE{"UNKNOWN"});
}


$status = GetOptions( "warn=s", \$warn,
"crit=i", \$crit);


open(PS, "/usr/bin/vmstat 1 4 | egrep -v '[a-z,A-Z]|-' |egrep '[0-9]' |") || return 1;
while (<PS>) {
(undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$idle,undef) = split(/[\t \n]+/);
$tidle = $tidle + $idle;
}
$usage = $tidle / 4;

if ($usage >= $crit) {

printf("CRITICAL - CPU usage at $usage% | 'CPU Load'=$usage%;$warn;$crit;0;100\n");
exit($STATUSCODE{"CRITICAL"});
}

elsif ($usage >= $warn) {

printf("WARNING - CPU usage at $usage% | 'CPU Load'=$usage%;$warn;$crit;0;100\n");
exit($STATUSCODE{"WARNING"});
}

elsif ($usage < $warn) {

printf("OK - CPU usage at $usage% | 'CPU Load'=$usage%;$warn;$crit;0;100\n");
exit($STATUSCODE{"OK"});
}

else {
printf("UNKNOWN - unable to determin usage\n");
exit($STATUSCODE{"UNKNOWN"});
}

 =================================================================

root #/opt/iexpress/nagios/libexec >vmstat 1 4
procs memory page faults cpu
r b w avm free re at pi po fr de sr in sy cs us sy id
5 6 0 23693444 24475061 0 0 9 0 0 0 0 23909 1509482 63321 15 10 74
5 6 0 23693444 24699477 0 0 1 0 0 0 0 21800 779633 13934 14 12 75
5 6 0 23693444 24781023 0 0 1 0 0 0 0 21439 762179 15067 10 8 82
5 6 0 23693444 24478642 0 0 1 0 0 0 0 21385 829326 16418 15 15 70

root #/opt/iexpress/nagios/libexec >/opt/iexpress/nagios/libexec/check_hpux_cpu.pl -w 80 -c 90
OK - CPU usage at 11.25% | 'CPU Load'=11.25%;80;90;0;100

 

 

1 REPLY
chindi
Respected Contributor
Solution

Re: Nagios graph for CPU utilisation

Have asked this question in Nagios forums.