Monitoring Sun One Web Server Active Threads

30 November -0001
I recently ran I recently ran into a situation where I had to monitor the number of active threads on a Sun One Web Server. We were having a problem with garbage collection taking up a lot of resources and causing a spike in active threads on the server. While solutions like MRTG could provide some very useful information, it required constantly scanning over the graphs. We wanted a solution that would monitor SNMP reports in the same way as MRTG, but that would analyze results and send emails out if there was a spike in active threads (as determined by comparing the difference between idle threads and total thread count). Although I investigated several native reporting options, include perfDump and stats-xml, I decided that utilizing the existing SNMP statistics would have the smallest overall load impact. The perl script used for task is listed below:
#! /usr/bin/perl
use strict;
use Net::SNMP;
use Net::SMTP;
my ($session, $error) = Net::SNMP->session(
-hostname  => shift || 'your.full.host.name',
-community => shift || 'yourCommunity',
-port      => shift || 161
);
if (!defined($session)) {
printf("ERROR: %s.\n", $error);
exit 1;
}
#iwsProcessThreadIdle 
my $idleThreads = '1.3.6.1.4.1.1450.1.60.3.1.4.1.1';
my $result = $session->get_request(
-varbindlist => [$idleThreads]
);
if (!defined($result)) {
printf("ERROR1: %s.\n", $session->error);
$session->close;
exit 1;
}
#debug:
#printf("Idle threads for host '%s' is %s\n",
#   $session->hostname, $result->{$idleThreads}
#);
my $idle = $result->{$idleThreads};
#iwsProcessThreadCount 
my $threadCount = '1.3.6.1.4.1.1450.1.60.3.1.3.1.1';
my $result = $session->get_request(
-varbindlist => [$threadCount]
);
if (!defined($result)) {
printf("ERROR1: %s.\n", $session->error);
$session->close;
exit 1;
}
#debug:
#printf("Thread Count for host '%s' is %s\n",
#   $session->hostname, $result->{$threadCount}
#);
my $descrepency = $result->{$threadCount} - $idle;
#printf("Active is %s\n", $descrepency);
$session->close;
if ($descrepency > 35) {
    # Connect to the server
    my $ServerName = 'yourSMTPserver';
    my $smtp = Net::SMTP->new($ServerName) ;
    die "Couldn't connect to server" unless $smtp ;
    my $MailFrom = "username\@domain.tld" ;
    my @MailTo = ("user1\@domain.tld","user2\@domain.tld");
    $smtp->mail( $MailFrom ) ;
    $smtp->to( @MailTo ) ;
    # Send the message
    $smtp->data("Active thread cnt is $descrepency\n\n") ;
    # Send the termination string
    $smtp->dataend() ;
    $smtp->quit() ;
}

   exit 0;