[Nagios-devel] Submission: plugin for java processes

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] Submission: plugin for java processes

Post by Guest »

Hi,

I have sent the message below once before, but I probably did something
wrong since it didn't appear on the mailing list. I hereby resend it.

Wim Rijnders.

========

Hi all,

I hereby submit a plugin perl-script for monitoring java processes. I
included the script below this message.

The notable characteristic of this script is that it checks the startup
class for the java application instead of the command name, which in the
case of java applications is always 'java' (possibly with path). It is
also possible to to specify warning and critical ranges for the number
of processes (or threads) running for a given application.

I use this plugin script to check for server applications without a
permanent port address. It has also proven useful for monitoring Tomcat
and jBoss, though other monitoring solutions exist and may be better in
this case.

The script has been tested with NetSaint and appears to work fine on our
network. Feedback and constructive criticism are sincerely welcomed.

Regards,

Wim Rijnders

======= check_javaproc =====

#!/usr/bin/perl -wT
#
# Author: Wim Rijnders, 17-10-2002
#
# Description:
# -----------
#
# Nagios host script to check if any specified java processes are
running.
#
# Implementation Notes:
# ---------------------
#
# check_disk_smb was used as a starting point, since it was written in
perl.
#
# This script has been created and tested on Linux RH 7.1.
#
# I tried OS-X Darwin (BSD), but the ps command works differently.
# Notably, you can't get a combined list of child processes. The best
approach
# appears to be to use 'ps -wwaxo command' combined with 'ps -M' (or
suchlike)
#
########################################################################
####

BEGIN {
if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) {
$runtimedir = $1;
$PROGNAME = $2;
}
}

require 5.004;
use POSIX;
use strict;
use Getopt::Long;
use vars qw($opt_w $opt_c $verbose $classname);
use vars qw($PROGNAME);
use lib $main::runtimedir;
use utils qw($TIMEOUT %ERRORS &print_revision &support &usage);

sub getJavaList ();
sub check_ranges ($ $ $ $);

Getopt::Long::Configure('bundling', 'no_ignore_case');
GetOptions
("V|version" => \&version,
"h|help" => \&help,
"v|verbose" => \$verbose,
"w|warning=s" => \$opt_w,
"c|critical=s" => \$opt_c,
"n|name=s" => \$classname
);


my $state = 'OK';
my $min_warn = undef
my $max_warn = undef;
my $min_crit = undef;
my $max_crit = undef;


($opt_w) || ($opt_w = shift);
check_ranges($opt_w,\$min_warn, \$max_warn, "warning");
($opt_c) || ($opt_c = shift);
check_ranges($opt_c,\$min_crit, \$max_crit, "critical");


#
# Determine # of running processes for the java programs that interest
us.
#
my @javalist = getJavaList();

my $total = 0;
my $msgout = "";
my @fields;

if ( defined $classname ) {

#filter out a single java process based on class name
foreach (@javalist) {
@fields = split(/\s+/, $_);
$total = $fields[-1] and last if $classname eq
$fields[0];
}
$msgout .= "$total processes for $classname\n";
} else {
#Handle all java processes
$msgout .= "\n";
foreach (@javalist) {
@fields = split(/\s+/, $_);

$total += $fields[-1];
$msgout .= " $fields[-1] processes for ";
$msgout .= (scalar @fields > 1)? $fields[0] : "unknown"
;
$msgout .= "\n";
}
my $msgtotal = "$total java processes for ". scalar @javalist .
" applications";

if ( defined $verbose ) {
$msgout = $msgtotal . $msgout;
} else {
$msgout = $msgtotal;
}

}

#
# Set the state with the data we now have accumulated
# Note that due to the order of testing, warnings have precedence over
# criticals. This is logical, since you should be able to create a
criticals
# range which encompasses a warning range. eg. following should be
possible:
#
# check_javaproc -w 5:10 -c 3:12
# proper specification of the ranges is the responsibility of the script
user.
#
$state = 'CRITICAL' if (defined $min_crit && $total $max_crit);
$state = 'CRITICAL' if (!defined $min_crit && !defined $max_crit &&
$total==0 );
$state = 'WARNING' if (defined $min_warn && $total <

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: wim.rijnders@topficie.nl
Locked