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.

Richard Majece said…
By the way, on you can read more about 1000 word essay writing. It's quite important information for students
jenifferleio12 said…
Before Commenting, I wanna say thank you for providing this great information. I feel too good to read it this awesome blog. Keep sharing this type of content.
ashleyleio123 said…
These type of articles keeps the users interest in the website. I found this one pretty fascinating and it should go into my collection. I am Impressed. Please keep going to write more content..

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 …

Running a Django Application on Windows Server 2012 with IIS

This is a first for me since under normal circumstances we run all our Django applications on Linux with Nginx, but we're in the process of developing an application for another department and due to the requirements around this project, we'll be handing the code off to them to deploy. They don't have any experience with Linux or web servers other than IIS, so I recently took up the challenge of figuring out how to run Django applications on Windows Server 2012 with IIS.

Based on the dated or complete lack of information around this I'm assuming it's not something that's very common in the wild, so I thought I'd share what I came up with in case others need to do this.

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Assumptions and CaveatsThe operating system is Windows Server 2012 R2, 64-bit. If another variant of the operating system is being used, these instructions may not work properly.All of the soft…

Fixing DPI Scaling Issues in Skype for Business on Windows 10

My setup for my day job these days is a Surface Pro 4 and either an LG 34UC87M-B or a Dell P2715Q monitor, depending on where I'm working. This is a fantastic setup, but some applications have trouble dealing with the high pixel density and don't scale appropriately.
One case in point is Skype for Business. For some reason it scales correctly as I move between the Surface screen and the external monitor when I use the Dell, but on the LG monitor Skype is either massive on the external monitor, or tiny on the Surface screen.
After a big of digging around I came across a solution that worked for me, which is to change a setting in Skype's manifest file (who knew there was one?). On my machine the file is here: C:\Program Files\Microsoft Office\Office16\LYNC.EXE.MANIFEST
And the setting in question is this:
Which I changed to this: <dpiAware>False/PM</dpiAware>
Note that you'll probably have to edit the file as administr…