« New HOWTO Article on Disabling Trace and Track on a BigIP | Main | Groovy 1.6.5 is out »


Tomcat Management: Basic Tomcat Interrogation Using Jmx4Perl

Many of us have scores, hundreds, or more tomcat servers sitting on our network and sometimes (often, for me) the naming conventions we might use for our servers are not necessarily descriptive enough for us to figure out what applications that server might be running. 

I first started writing about the goodness that is Jmx4Perl a couple weeks ago.  I've been playing with it off and on ever since and I have not lost my initial favorable impressions.  I thought it would be a useful learning exercise writing some basic script that I would use on a semi-regular basis at work—I do not necessarily care to write something that I won't ever use again once I've been able to successfully execute it.   Since I have plenty of tomcat servers on my network now, things have gotten to the point that if someone in our NOC reports an issue with server297, a simple running of the following script is enough to freshen my memory as to what applications this server is hosting.  Heck, it may even turn out to be something that will grow into a full server interrogation script in the future, like cryptonark did.

Below is a basic Jmx4Perl server interrogation script I'm calling sooth.pl. It's designed so that you execute sooth.pl $host $port and it will tell you the Tomcat version string and will print out all the webapps it finds. The script calls a couple of the actual mbeans and attributes, to demonstrate syntax when no suitable alias exists. I'd like to thank Roland Huß for publishing such a useful module that lowers the learning curve for folks like me who want to take advantage of the utility that JMX provides but who don't necessarily have the time to invest in doing it the "Java-way" right now.

#!/usr/bin/env perl 
#         FILE:  sooth.pl
#        USAGE:  ./sooth.pl $host $port  
#  DESCRIPTION:  Demonstrates Jmx4Perl.
#        NOTES:  ---
#       AUTHOR:  Chris Mahns 
#      COMPANY:  techstacks.com
#      VERSION:  0.1
#      CREATED:  09/06/2009

use strict;
use warnings;
use feature ':5.10';

use JMX::Jmx4Perl;
use JMX::Jmx4Perl::Alias;

my $host = $ARGV[0];
my $port = $ARGV[1];

my $usage = "Usage:  $0 <host> <port>";

if ( !@ARGV ) {
  say $usage;
  exit 0;

my $jmxconn = JMX::Jmx4Perl->new(url => "http://$host:$port/j4p");
my $version = $jmxconn->get_attribute( {
  mbean => "Catalina:type=Server",
  attribute => "serverInfo",
  } );

my $contexts = $jmxconn->get_attribute( {
  mbean => "Catalina:port=8080,type=Mapper",
  attribute => "contextNames",
  } );

say "";
say "$host is running: $version";
say "";
say "The following webapp contexts were found";

foreach (@$contexts) {
say $_;


TrackBack URL for this entry:

Listed below are links to weblogs that reference Tomcat Management: Basic Tomcat Interrogation Using Jmx4Perl: