Skip to main content

Monitoring Tomcat with Java VisualVM

One of the best kept secrets that's bundled with your Java 6 JDK is VisualVM. VisualVM is an absolutely fantastic, free monitoring tool for Java that you may not realize is right under your nose.

In a nutshell, when you fire up VisualVM it provides you with a ton of monitoring tools for everything running on the JVM. By default VisualVM will monitor the VM from which it's launched, so if for example you launch VisualVM from the bin directory of jdk1.6.0_17, then anything using that JVM will show up as a process in VisualVM that can be monitored. Note that in some cases certain processes will not appear in VisualVM, which is the real point of this post; I'll get to that in a moment.

I'm attaching a few screenshots to this post. The first shows what VisualVM looks like when I fired it up just now on my Linux laptop, the second shows a snapshot of the main monitor screen (in this case I'm monitoring Tomcat), and the third shows a snapshot of the thread monitoring screen (note the Open BlueDragon threads!). VisualVM can also take and load snapshots so you really hone in on problems at the VM level quite easily.

One major point I'd like to make is that VisualVM will monitor any Java application running on the JVM. So in the CFML world this means if you have OpenBD, Railo, or ColdFusion running, they can all be monitored quite nicely using VisualVM.

VisualVM can also monitor remote JVMs via JMX (Java Management Extensions), so if you're having trouble on a remote server and want to see what's going on, as long as the JMX ports are open and accessible you can launch VisualVM from your local machine and connect to the remote VM. Note that monitoring is a very lightweight process so VisualVM can be used to monitor production servers with virtual no impact. Visual VM also does profiling, however, which is a much more heavyweight process. It provides a huge amount of useful information, but should be used only when absolutely needed on production servers since it will have a noticeable impact on performance.

Now to the real point of this post. When I launched VisualVM on a Windows 2003 server today I was surprised that Tomcat didn't show up as a process running under the VM. Turns out that if you install Tomcat as a service, even if it's running under the same user account that you used to launch VisualVM, Tomcat won't appear by default in the VisualVM process list.

Luckily it's easy enough to resolve. Simply open the Tomcat Configuration application and add the following in the Java Options box on the Java tab:

After making this change you do have to restart Tomcat.

This will enable JMX in Tomcat and allow VisualVM to connect to it. You can choose any port you like, and note that if you want to use SSL or authentication you would set those options to true. I haven't personally messed with authentication so I'm not sure what that authenticates against, but know that if you want to have JMX available on a production system that you can secure it this way, or of course through firewall rules.

With JMX enabled in Tomcat you then go into VisualVM, add a new JMX connection, and point it to localhost:8086 (or whatever port you set JMX to run on). That's it--you're now monitoring Tomcat!

VisualVM is a great, free tool that you likely already have on your machine, so you really owe it to yourself to check it out.


garyrgilbert said…
I've been using jconsole to check the thread that are running on the VM, will have to check out VisualVM, thanks for posting this matt. Being able to monitor the JVM in this fashion will give us real insight on tweaking our settings.
Peter J. Farrell said…
Ok, this is too freaky Matt. I fired up VisualVM tonight because I needed to check on a possible memory leak I was seeing. The ironic part is that I didn't see that you posted this until about 30 minutes *after* I stat'ed I was using VisualVM. Ok, we think too much alike!
Matthew Woodward said…
Thanks--I've been meaning to check out jconsole more. Haven't really dug into it yet.
Matthew Woodward said…
Dang. That is a bit freaky. ;-)
Kurt Wiersma said…
I believe that VisualVM replaces jconsole as of JVM 1.6. It should have all the features of jconsole plus more is what I have heard.
Matthew Woodward said…
Thanks--good to know! I was getting everything I needed from VisualVM so I hadn't looked into other tools yet.
marcesher said…
Kurt, I'm not su sure that it's a replacement. Visually it shows most of the same stuff, albeit it not as granular. The big thing missing though are the different operations you can invoke on registered MBeans (via the 'operations' tree nodes in jconsole).I'm liking VisualVM, but I find myself in jconsole a fair amount still. However, there are plugins -- go to Tools, plugins -- and there's a jconsole plugin. But I have so far been unsuccessful at getting them to install.
yardus said…
@marcesher Once you install the VisualVM-MBeans plugin you will get all the MBeans functioanlity available in JConsole. Although the operations are not available as an MBean subtree but they are represented as the MBean subtab (an MBean has 4 subtabts - Attributes, Operations, Notifications and Metadata)
Matthew Woodward said…
Cool--thanks for the info!
marcesher said…
@yardus I did find the different plugins and am really liking jvisualvm. However, one problem I've run into -- and haven't yet spent the time to figure out the best way to solve it -- is on production servers with no external access. JVisualVM needs to go out and download those plugins, and on our production servers, I can't do that. What I don't get is why these things aren't installed by default. What's the benefit of keeping them "out there" and forcing people to fetch them?And is there a way to install them without internet access?
boron747 said…
hello, i've connected visualvm to tomcat via jmx port 8086 per above guide, however I don't see the profiler tab/option. I do see profiler tab/option for other java apps. is anyone else having this problem?
tedsteinmann said…
Great post, thank you!
techcooker said…
@marcesher never ever run profiler tool on the same machine you want to profile as profilers swallow the machine's resources, it's strongly recommended to profile servers remotely.
ARM said…

Thanks for the post.
Exactly what I am looking for.


Popular posts from this blog

Installing and Configuring NextPVR as a Replacement for Windows Media Center

If you follow me on Google+ you'll know I had a recent rant about Windows Media Center, which after running fine for about a year suddenly decided as of January 29 it was done downloading the program guide and by extension was therefore done recording any TV shows.

I'll spare you more ranting and simply say that none of the suggestions I got (which I appreciate!) worked, and rather than spending more time figuring out why, I decided to try something different.

NextPVR is an awesome free (as in beer, not as in freedom unfortunately ...) PVR application for Windows that with a little bit of tweaking handily replaced Windows Media Center. It can even download guide data, which is apparently something WMC no longer feels like doing.

Background I wound up going down this road in a rather circuitous way. My initial goal for the weekend project was to get Raspbmc running on one of my Raspberry Pis. The latest version of XBMC has PVR functionality so I was anxious to try that out as a …

Setting Up Django On a Raspberry Pi

This past weekend I finally got a chance to set up one of my two Raspberry Pis to use as a Django server so I thought I'd share the steps I went through both to save someone else attempting to do this some time as well as get any feedback in case there are different/better ways to do any of this.

I'm running this from my house (URL forthcoming once I get the real Django app finalized and put on the Raspberry Pi) using I don't cover that aspect of things in this post but I'm happy to write that up as well if people are interested.

General Comments and Assumptions

Using latest Raspbian “wheezy” distro as of 1/19/2013 (’lll be using Nginx ( as the web server/proxy and Gunicorn ( as the WSGI serverI used heavily as I was creating this, so many thanks to the author of that tutorial. If you’re looking for more details on …

The Definitive Guide to CouchDB Authentication and Security

With a bold title like that I suppose I should clarify a bit. I finally got frustrated enough with all the disparate and seemingly incomplete information on this topic to want to gather everything I know about this topic into a single place, both so I have it for my own reference but also in the hopes that it will help others.Since CouchDB is just an HTTP resource and can be secured at that level along the same lines as you'd secure any HTTP resource, I should also point out that I will not be covering things like putting a proxy in front of CouchDB, using SSL with CouchDB, or anything along those lines. This post is strictly limited to how authentication and security work within CouchDB itself.CouchDB security is powerful and granular but frankly it's also a bit quirky and counterintuitive. What I'm outlining here is my understanding of all of this after taking several runs at it, reading everything I could find on the Internet (yes, the whole Internet!), and a great deal…