mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-28 08:04:36 +02:00
Fix #5519
This commit is contained in:
parent
2aef0775d2
commit
bfeec3ca95
@ -56,11 +56,12 @@ sub new {
|
|||||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
||||||
"timeout:s" => { name => 'timeout', default => 30 },
|
"timeout:s" => { name => 'timeout', default => 30 },
|
||||||
"sudo" => { name => 'sudo' },
|
"sudo" => { name => 'sudo' },
|
||||||
"command:s" => { name => 'command', default => 'cat' },
|
"command:s" => { name => 'command', default => 'tail' },
|
||||||
"command-path:s" => { name => 'command_path' },
|
"command-path:s" => { name => 'command_path' },
|
||||||
"command-options:s" => { name => 'command_options', default => '/proc/loadavg 2>&1' },
|
"command-options:s" => { name => 'command_options', default => '-n +1 /proc/loadavg /proc/stat 2>&1' },
|
||||||
"warning:s" => { name => 'warning', default => '' },
|
"warning:s" => { name => 'warning', default => '' },
|
||||||
"critical:s" => { name => 'critical', default => '' },
|
"critical:s" => { name => 'critical', default => '' },
|
||||||
|
"average" => { name => 'average' },
|
||||||
});
|
});
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
@ -109,7 +110,9 @@ sub run {
|
|||||||
command_options => $self->{option_results}->{command_options});
|
command_options => $self->{option_results}->{command_options});
|
||||||
|
|
||||||
my ($load1m, $load5m, $load15m);
|
my ($load1m, $load5m, $load15m);
|
||||||
if ($stdout =~ /([0-9\.]+)\s+([0-9\.]+)\s+([0-9\.]+)/) {
|
my ($msg, $cpu_load1, $cpu_load5, $cpu_load15);
|
||||||
|
|
||||||
|
if ($stdout =~ /\/proc\/loadavg.*?([0-9\.]+)\s+([0-9\.]+)\s+([0-9\.]+)/ms) {
|
||||||
($load1m, $load5m, $load15m) = ($1, $2, $3)
|
($load1m, $load5m, $load15m) = ($1, $2, $3)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,29 +121,54 @@ sub run {
|
|||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
my $exit1 = $self->{perfdata}->threshold_check(value => $load1m,
|
if (defined($self->{option_results}->{average})) {
|
||||||
threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
|
my $countCpu = 0;
|
||||||
my $exit2 = $self->{perfdata}->threshold_check(value => $load5m,
|
|
||||||
threshold => [ { label => 'crit5', 'exit_litteral' => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
|
|
||||||
my $exit3 = $self->{perfdata}->threshold_check(value => $load15m,
|
|
||||||
threshold => [ { label => 'crit15', 'exit_litteral' => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
|
|
||||||
|
|
||||||
|
$countCpu++ while ($stdout =~ /^cpu\d+/msg);
|
||||||
|
|
||||||
|
if ($countCpu == 0){
|
||||||
|
$self->{output}->output_add(severity => 'unknown',
|
||||||
|
short_msg => 'Unable to get number of CPUs');
|
||||||
|
$self->{output}->display();
|
||||||
|
$self->{output}->exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
$cpu_load1 = sprintf("%0.2f", $load1m / $countCpu);
|
||||||
|
$cpu_load5 = sprintf("%0.2f", $load5m / $countCpu);
|
||||||
|
$cpu_load15 = sprintf("%0.2f", $load15m / $countCpu);
|
||||||
|
$msg = sprintf("Load average: %s [%s/%s CPUs], %s [%s/%s CPUs], %s [%s/%s CPUs]", $cpu_load1, $load1m, $countCpu,
|
||||||
|
$cpu_load5, $load5m, $countCpu,
|
||||||
|
$cpu_load15, $load15m, $countCpu);
|
||||||
|
} else {
|
||||||
|
$cpu_load1 = $load1m;
|
||||||
|
$cpu_load5 = $load5m;
|
||||||
|
$cpu_load15 = $load15m;
|
||||||
|
|
||||||
|
$msg = sprintf("Load average: %s, %s, %s", $cpu_load1, $cpu_load5, $cpu_load15);
|
||||||
|
}
|
||||||
|
|
||||||
|
my $exit1 = $self->{perfdata}->threshold_check(value => $cpu_load1,
|
||||||
|
threshold => [ { label => 'crit1', 'exit_litteral' => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
|
||||||
|
my $exit2 = $self->{perfdata}->threshold_check(value => $cpu_load5,
|
||||||
|
threshold => [ { label => 'crit5', 'exit_litteral' => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
|
||||||
|
my $exit3 = $self->{perfdata}->threshold_check(value => $cpu_load15,
|
||||||
|
threshold => [ { label => 'crit15', 'exit_litteral' => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
|
||||||
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
|
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
|
||||||
$self->{output}->output_add(severity => $exit,
|
$self->{output}->output_add(severity => $exit,
|
||||||
short_msg => sprintf("Load average: %s, %s, %s", $load1m, $load5m, $load15m));
|
short_msg => $msg);
|
||||||
|
|
||||||
$self->{output}->perfdata_add(label => 'load1',
|
$self->{output}->perfdata_add(label => 'load1',
|
||||||
value => $load1m,
|
value => $cpu_load1,
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1'),
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1'),
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1'),
|
||||||
min => 0);
|
min => 0);
|
||||||
$self->{output}->perfdata_add(label => 'load5',
|
$self->{output}->perfdata_add(label => 'load5',
|
||||||
value => $load5m,
|
value => $cpu_load5,
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
|
||||||
min => 0);
|
min => 0);
|
||||||
$self->{output}->perfdata_add(label => 'load15',
|
$self->{output}->perfdata_add(label => 'load15',
|
||||||
value => $load15m,
|
value => $cpu_load15,
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
|
||||||
min => 0);
|
min => 0);
|
||||||
@ -167,6 +195,10 @@ Threshold warning (1min,5min,15min).
|
|||||||
|
|
||||||
Threshold critical (1min,5min,15min).
|
Threshold critical (1min,5min,15min).
|
||||||
|
|
||||||
|
=item B<--average>
|
||||||
|
|
||||||
|
Load average for the number of CPUs.
|
||||||
|
|
||||||
=item B<--remote>
|
=item B<--remote>
|
||||||
|
|
||||||
Execute command remotely in 'ssh'.
|
Execute command remotely in 'ssh'.
|
||||||
@ -197,7 +229,7 @@ Use 'sudo' to execute the command.
|
|||||||
|
|
||||||
=item B<--command>
|
=item B<--command>
|
||||||
|
|
||||||
Command to get information (Default: 'cat').
|
Command to get information (Default: 'tail').
|
||||||
Can be changed if you have output in a file.
|
Can be changed if you have output in a file.
|
||||||
|
|
||||||
=item B<--command-path>
|
=item B<--command-path>
|
||||||
@ -206,7 +238,7 @@ Command path (Default: none).
|
|||||||
|
|
||||||
=item B<--command-options>
|
=item B<--command-options>
|
||||||
|
|
||||||
Command options (Default: '/proc/loadavg 2>&1').
|
Command options (Default: '-n +1 /proc/loadavg /proc/stat 2>&1').
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user