Creating Custom Tools for Monitoring Apache Tomcat, Apache Tomcat Admin

posted by MSacks on May 17, 2010 03:07 PM

Often times a developer or operations professional needs access to monitor a Tomcat instance for purposes of capacity planning, troubleshooting, and performance tuning. There are many tools available already for Tomcat, some of them open source, and others paid for. Some tools are simple and others are complex management suites.

There are comprehensive monitoring suites available that monitor and manage Tomcat, and do it well; however, there is always a benefit to being able to create your own custom Tomcat/application management tools. The first advantage is that you get exactly what you want out of your utility. In my example, I wanted to have a way to browse a Tomcat server’s Java Management Extensions’ MBeans with a hierarchical, bash-like navigation. This allows me to quickly find and diagnose problems with my Tomcat server or custom applications running within Tomcat, and is more precise than trending those MBeans over time using a more comprehensive monitoring suite. I liken it to purchasing a ready-made suit, or having one custom tailored to your exact specification. It just feels better sometimes, and other times it is not practical.

Why Create Your Own Custom Tools

Many utilities will not provide the specific feature that you need. There are usually a host of open source or commercial utilities for anything that one goal any developer or operations professional may want to achieve; however, often times that utility will not integrate well into their existing infrastructure, or not play well with automated processes that are pre-existing in the enterprise. In such cases, a custom utility can come in handy. Writing your own tools from scratch is a quick solution to a specific problem, and cuts out a lot of the fat. For simple tools, the complexity risk argument just isn't there, and in the time it takes to write a simple custom application.

The Jython JMX Client

The application is a very simple command line JMX Client, and by no means a perfect implementation. JConsole, or VisualVM is typically the method of choice for viewing and manipulating MBeans amongst Java Developers. The only problem with these graphical utilities is that they are not automatable and cannot query hundreds or thousands of MBeanServers. Enter the jythonJMXClient.

I created the jythonJMXClient primarily for demonstrating why writing custom tools for monitoring Tomcat is a useful practice. It is simple in design, and only performs a few set functions. It is easily extensible, and by maintaining it's simplicity and only focusing on a few set functions, it enables the user to perform easily mold the application to their needs.

I chose to write my application in Jython, which is an implementation of Python on the Java platform. It allows me to utilize the rapid development abilities of Python while still being able to access the JMX API's used for monitoring and managing Java applications, and in this case, Tomcat.

Using the Jython JMX Client

The Jython JMX Client's sources are available for download at Patches are welcome. Rather than dig into the source code, I will demonstrate how the application works here. 

Step 1: Invoke the JMX Client) java -jar ~msacks/jython2.5rc2/jython.jar
Step 2: Make a Connection to the MBeanServer) jmx> connect -h -p 9999
Step 3: Query the MBean and Attribute)
jmx> getAttribute -m java.lang:type=Memory -a HeapMemoryUsage
contents={committed=5459968, init=0, max=66650112, used=4079208})


jmx> getAttribute -m java.lang:type=Threading -a PeakThreadCount


jmx> getAttribute -m Catalina:type=ThreadPool,name=http-8080 -a currentThreadsBusy

Now with the beauty of Python's cmd library, I can also pass the commands in a text file if I want to automate things a bit more than use the jythonJMXClient in an ad-hoc example as I have here.

#sequence of commands for the jythonJMX Client
connect -h -p 9999
getAttribute -m Catalina:type=ThreadPool,name=http-8080 -a currentThreadsBusy
getAttribute -m java.lang:type=Memory -a HeapMemoryUsage
connect -h -p 8888
getAttribute -m Catalina:type=ThreadPool,name=http-8080 -a currentThreadsBusy
#ad infinitum

The idea is simple, I write, I test, I use my new utility. Writing you own custom applications is more like using an exacto knife where it’s need whereas before all you had was a hammer.

Jython JMX Client's Weaknesses and Strengths

There are already some command line JMX clients out there, jmxsh, jmxterm, and JBoss's twiddle. All of which are fantastic utilities, but I wanted to show how one might write a utility for querying Tomcat

The jythonJMXClient is simple, yet it has a few key shortcomings, mostly authentication, SSL support, and the ability to invoke methods using JMX. It was created primarily as a querying tool for gathering metrics about a running Tomcat instance, and not as a comprehensive management tool.

It’s advantages are that it’s highly customizable to your liking, and is very precise. For operations professionals or developers who do not want to have to remember their entire MBean hierarchy and structure (especially when creating many custom MBeans) it provides a precise and simple tool that is extremely easy to use. It is much more lightweight and precise than something such as JConsole, for example. Also, many folks prefer to use the command line, which gives it automation abilities and is easier to use for some people than a Graphical User Interface.


Writing simple and effective tools such as the jythonJMXClient will make your life infinitely easier when it comes to automation and querying a Tomcat server. I can now query a command line application which will allow me to access specific metrics in an automated fashion. I can integrate it with any other custom tools which I might need to perform some kind of action on, such as send an email based on some criteria, restart the server, or anything I like. What I would like to include in the future is including management facilities for calling object methods through JMX, so I have a complete monitoring and management tool that I can customize and extend to my liking.

Looking Forward

In future versions of jmxCmd, we will add functionality for invoking remote methods via JMX to the command line, and introduce the management aspect of the utility and how to write custom methods in JMX.

Matthew Sacks is an Application System Administrator at, and focuses on administering, monitoring and managing high-volume, high-traffic production Web sites. He is also the Founder and Editor of, a blog on System Administration, Web Application Development and Software Engineering. He is an active member in the USENIX The Advanced Computing Systems Professional and Technical Association, and has contributed to such publications as Linux Pro Magazine, Sys Admin Magazine, and InformIT.

Comments - Global information

f5f6fdf8e039a087cfd771b09f83bab7 Hello!,

Thanks for the info Matt. It

Thanks for the info Matt. It is such tips and tutorials from tech geeks like you that help amateurs keep going. You simplify the task superbly. More techies should follow your footsteps and share the knowledge for the greater good. click this link

Software avchd converter

Software avchd converter convert avchd video files to avi, mp4, wmv, mov mod converter free download to convert HD camcorder files. mts to avi mp4 mov mkv iMovie, FCP/FCE with mts converter, so to convert mts files for your PC and mobiles. v3

great post

Really, Hollywood Celebrity And Designers Real Leather Jackets | Top Celebrity Jackets i appreciate the effort you made to share the knowledge. The topic here i found was really effective to the topic which i was researching for a long time.

baixar pou hacker This is

baixar pou hacker This is important, though it's necessary to help you head over to it weblink: clash of clans tipps und tricks

I recently came across your

I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you. buyfollowers | buy small instagram likes


how to get followers That can feel great to learn these kinds of useful and also special posts on your own sites. views

los mejores videos

Estan aqui

videos porno



videos xxx


Thanks for information! I enjoyed reading!
bloodshot eyes eye care professional

I’m impressed, I have to

I’m impressed, I have to admit. Rarely do I encounter a blog that’s both equally educative and engaging, and let me tell you, you've hit the nail on the head. The issue is something which too few men and women are speaking intelligently about. I'm very happy I stumbled across this in my hunt for something relating to this.
Mortgage Broker Calgary

It’s hard to find

It’s hard to find well-informed people in this particular topic, but you seem like you know what you’re talking about! Thanks
Edmonton Mortgage Broker
Life Insurance Vancouver
Life Insurance Calgary


how to get more favorites and retweets on twitter This is helpful, nonetheless it can be crucial so that you can check out the following website: twitter followers buy

Post new comment

This question is for testing whether you are a human visitor and to prevent automated spam submissions.