����JFIF��x�x����'
| Server IP : 78.140.185.180 / Your IP : 216.73.216.170 Web Server : LiteSpeed System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64 User : builderbox ( 1072) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/1630575/root/proc/1630575/root/proc/self/root/usr/lib64/nagios/plugins/extra/ |
Upload File : |
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw(say);
use Carp;
use Getopt::Long;
use File::Slurp;
my ( $raw, $current, $gain, $limits, $is_percent, $flag, @perfdata );
my %ERRORS = ( 'OK' => 0, 'WARNING' => 1, 'CRITICAL' => 2, 'UNKNOWN' => 3 );
sub help {
print <<EOT;
$0 [-w/--warn 15,0,-7 -c/--crit 100,70,50]
Plugin accepts three values of overused cores for warn and crit to check load average
first param: la1
second param: la5
third param: la15
The plugin calculates the limit relative to the number of cpu cores of the server.
Plugin may work in two mode: pecentage or quantitative.
Parameters of plugin may accept integer and non-integer numbers including negatives for both modes.
To use percentage mode symbol '%' must be specified in value strings.
If at least one value has a '%' symbol, the percentage mode is used.
Default values in relative mode:
warn: 15\%,0\%,-7\%
crit: 100\%,70\%,50\%
Allowed formats:
--warn 1
--crit 1\%,-2\%
For any unspecified params, corresponding default will be used
EOT
exit 3;
}
GetOptions(
'h|help' => \&help,
'w|warn=s' => \$raw->{warn},
'c|crit=s' => \$raw->{crit}
);
help() if $raw->{warn} && $raw->{warn} !~ /\d+,?/;
help() if $raw->{crit} && $raw->{crit} !~ /\d+,?/;
$raw->{warn} //= '15%,0%,-7%';
$raw->{crit} //= '100%,70%,50%';
for my $type ( keys %$raw ) {
my $i = 0;
for ( split /,/, $raw->{$type} ) {
help() if $_ !~ m/(^-?\d*.{0,1}\d+%?)$/;
$i++;
my $val
= $i == 1 ? 'la1'
: $i == 2 ? 'la5'
: 'la15';
$gain->{$type}{$val} = $1 if $_ =~ m/(-?\d*.{0,1}\d+)/;
$is_percent = 1 if $_ =~ m/\%/;
# $is_percent->{w}{$val} = 1 if $_ =~ m/\%/;
}
}
my $cores = (map /^processor/, read_file("/proc/cpuinfo"));
my $lafile = read_file '/proc/loadavg';
( $current->{la1}, $current->{la5}, $current->{la15}, undef )
= split '\s', $lafile;
for my $type ( keys %$gain ) {
for my $val ( keys %{$gain->{$type}} ) {
# if ($is_percent->{$type}->{$val} {
if ($is_percent) {
$gain->{$type}{$val} /= 100;
$limits->{$type}{$val} = $cores + $cores * $gain->{$type}{$val};
}
else {
$limits->{$type}{$val} = $cores + $gain->{$type}{$val};
}
croak "Wrong value for $val found in $type parameter"
if $limits->{$type}{$val} < 0;
$flag->{$type}
= ( $current->{$val} > $limits->{$type}{$val} ) ? 1 : 0
if !$flag->{$type};
}
}
# prepare perfdata
for my $metric (keys %$current ) {
push @perfdata, "$metric=$current->{$metric};$limits->{warn}->{$metric};$limits->{crit}->{$metric}";
}
my $ERR
= $flag->{'crit'} ? 'CRITICAL'
: $flag->{'warn'} ? 'WARNING'
: 'OK';
my $result
= "$ERR - load average: $current->{la1}, $current->{la5}, $current->{la15}";
say $result . " | " . join( ";; ", @perfdata ) . ";;";
exit $ERRORS{$ERR};