Script to monitor too many instance of processes
Hello,
If your server have too many processes running for a single application here is the script that you can set in cron.
#!/usr/local/bin/perl
my $cmd=”ps -aef | grep -i java | grep -v grep | wc -l”;
$thread_count = `$cmd`;
chomp($thread_count);
$thread_count=~s/ //g;
$hostname=`hostname`;
print “thread count is $thread_count\n”;
if ($thread_count > 100){
print “inside the first 1f\n”;
for($flag = 0; $flag <=3;$flag++){
$mail =0;
$thread_count = `$cmd`;
chomp($thread_count);
$thread_count=~s/ //g;
print "thread count is $thread_count\n";
if ($thread_count > 100){
$mail = 1;
`sleep 180`;
}
}
}
print “Subject: Java Thread count high on $hostname\n”;
if ($mail == 1){
print “sending mail \n”;
open(MAIL, “|/usr/lib/sendmail -t”);
print MAIL “From: email\@domain.com\n”;
print MAIL “To: receiver\@domain.com,Nextreceiver\@domain.com\n”;
print MAIL “Subject: java Thread count high on $hostname\n”;
print MAIL “Open Deploy Thread count on $hostname value is $thread_count.\n\n”;
foreach (@output) {
chomp($_);
print MAIL “$_\n”;
}
close MAIL;
}
0,30 * * * * /script/process_moniter.sh