Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to monitor multiple running processes from ITO Application. 1

Status
Not open for further replies.

kidcrash

Technical User
Mar 27, 2002
15
US
Hi,

My question is concerning how to use 1 monitor to look for multiple processes to be running, and use a specific threshold for each process. I don't want to have to create a separate monitor for each process that I need to watch. I have was hoping that someone may have a script that I can use to do this.

thanks in advance,
Kidcrash

 
I don't think you can do that, my understanding is that a monitor can only have one threshold - so you can't monitor more than one process - individually - from a single monitor.

You could lump a bunch of processes together easily enough, writing a script that checks for them and sets the monitor value accordingly.

If I need to do this I've always used a logfile processor and monitored a logfile produced by a script I've written myself. The script puts nice, descriptive, messages in the log file that I then pick up and use in the template filter. Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
Hi Mike,

Can I get a copy of that script you created? I am not good at scripting or programming. I thought that I could run a Schedule to do a "ps -eaf > /tmp/logfile" and then build a logfile scraper to scrap the logfile with several conditions for all of the processes. The only problem is that I need the format to be different to grab the data for threshold monitoring. Since I don't know scripting, it causes me problems.

thanks in advance for your help,
Kidcrash
 
It's a Perl script - is that useful to you? Mike
"Experience is the comb that Nature gives us after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
[tt]
================================================================================
#!/usr/contrib/bin/perl

#
# p_check.pl
#
# Checks that a list of processes are running, prints an message on STDOUT
# for processes that are not.
#
# This script is designed to be run by a HP/OVO logfile processor; it should
# run pretty much as is on any unix platform with perl install, the ps
# command may have to be modified - but not much.
#
# Run the script using a template and direct its output to a file, monitor
# that file using the conditions searching for lines in the log starting
# with ERROR:
#
# usage: p_check.pl proc1 count proc2 count proc3 count
# eg: p_check.pl sendmail 1 vhand 1 user_proc 3
# The example above would check for a sendmail process, a vhand process and
# three copies of user_proc.
#

use strict;

my $ps_cmd = 'ps -e'; # get all running processes

my %ps_list;
my ($proc, $count);

print "OK: Checking command line.\n";
while(@ARGV){
$proc = shift or die; # get stuff from command line
$count = shift or die;
print "DBG: $proc, $count\n";
$ps_list{$proc} = $count; # build a hash of things to do
}

# ok, now get a process list and check for the processes we care about
print "OK: Getting process list.\n";
open(PS,"$ps_cmd |") || die;
while(<PS>){
(undef, undef, undef, $proc) = split;
chomp($proc);
if(defined($ps_list{$proc})){ # if it's in the list
$ps_list{$proc} --; # knock one off its count
}
}

#
# If there's anything in %ps_list with a positive value, not enough instances
# of that process are running.
#

print &quot;OK: Reporting any errors.\n&quot;;
foreach $proc (keys %ps_list){
if($ps_list{$proc}){ # a non-zero count?
# yes, so print an error message
print &quot;ERROR: Not enough instances of $proc are running\n&quot;
if $ps_list{$proc} > 0;
print &quot;ERROR: Too many instances of $proc are running\n&quot;
if $ps_list{$proc} < 0;
} else {
print &quot;OK: Enough instances of $proc are running\n&quot;;
}
}
print &quot;OK: Finished\n&quot;;
exit 0;
[/tt]

Hope this is useful to you, and others. the first line needs to be changed to match where your copy of perl is stored. It requires Perl v5 as it stands, if only Perl 4 is available: delete 'use strict' line, remove the my from the 'my $ps_cmd = 'ps -e'; # get all running processes' line and delete the two other 'my' lines. Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Thanks Mike. I will use it. I appreciate your help on this matter.

Kidcrash
 
My pleasure Kidcrash, I'm sure you'll do the same for me or someone else, and probably quite soon as well :) Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
You can also use the default monitor template. you have to define a condition for every single process check. for excample:

1. monitor if 1 process is running (condition1: threshold 0/1)
2. monitor if 2 processes running (condition2: threshold 1/2)

and so on

bit complicated, but you can define a different text or criticality for all the alarms!!!!!!! sometimes usefull ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top