| Server IP : 118.27.122.120 / Your IP : 216.73.216.136 Web Server : Apache System : Linux web0216.sh.tyo1 4.18.0-553.141.2.lve.el7h.x86_64 #1 SMP Wed Jul 8 17:20:31 UTC 2026 x86_64 User : r4834334 ( 11094) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/proc/self/root/proc/thread-self/root/lib64/nagios/plugins/ |
Upload File : |
#!/usr/bin/perl -w
# Reik Keutterling
use strict;
use warnings;
use Getopt::Long;
my @return_codes = qw( OK WARNING CRITICAL UNKNOWN );
my ($warning, $critical, $string) = &get_cmd_params();
my ($warning_min, $warning_max) = (split(/:/, $warning), "0");
my ($critical_min, $critical_max) = (split(/:/, $critical), "0");
map{defined($_)?$_+0:0}($warning_min, $warning_max, $critical_min, $critical_max);
($warning_max, $warning_min) = ($warning_min, $warning_max) if ($warning_max == 0);
($critical_max, $critical_min) = ($critical_min, $critical_max) if ($critical_max == 0);
my $threads = 0;
my $status = 0;
my $msg = '';
if (open(PS_ELF, "ps -eLf|")) {
foreach (<PS_ELF>) {
if ($_ =~ m/\Q$string\E/ and $_ !~ m/\Q$0\E/) {
$threads++;
}
}
close(PS_ELF);
if ($threads > $critical_max or $threads < $critical_min) {
$status = 2;
}
elsif ($threads > $warning_max or $threads < $warning_min) {
$status = 1;
}
else {
$status = 0;
}
$msg = "$threads threads containing '$string'";
} else {
$status = 3;
$msg = 'ERROR';
}
print "$return_codes[$status] - $msg ","|threads=$threads;$warning_max;$critical_max;$status\n";
exit $status;
#######################################################################
sub get_cmd_params {
my ($warning, $critical, $string) = ('','','');
my $result = GetOptions( 'w=s' => \$warning,
'c=s' => \$critical,
'a=s' => \$string );
my $usage = <<EXIT;
Usage:
check_threads -w [<minthreads>:]<maxthreads> -c [<minthreads>:]<maxthreads> -a <string>
Examples:
check_threads -w 2:2 -c 2:1024 -a java
Warning if != 2 threads containing 'java'
Critical if < 2 or > 1024 threads
check_threads -w 10 -c 50 -a java
Warning if > 10 threads containing 'java'
Critical if > 50 threads
EXIT
die $usage if($warning eq '' || $critical eq '' || $string eq '');
return ($warning, $critical, $string);
}