How to monitor your local Java web application through JMX

Java Management Extensions (JMX) is a Java technology that supplies tools for monitoring applications. Monitoring a locally running Java web application is really straightforward.

You do not need any extra configuration to set up, you only need a tool called JConsole, and it’ll be able to see all your locally running JVMs and monitor them.

JConsole can be found in the bin directory inside your JDK’s installation directory. For me it is: C:\Program Files\Java\jdk1.8.0_91\bin 

Start jconsole.exe and you should see your local processes:

On this example screenshot, the first process is a Java web application which I started in a standalone tomcat. The second one is the process of JConsole itself.

Even you are running your application using the Maven tomcat plugin and not in a standalone tomcat, it’ll still work.

Select one of the processes and double click on it. You should see the management interface open up with a slew of useful statistics and information:

Troubleshooting

If you do not see any processes in the “Local Processes” list, please check out this post for a possible solution.

JConsole is not showing any local processes

JConsole is a great tool to monitor Java applications using JMX. One common issue that can happen, is that when you start JConsole, you don’t see any process in the “Local Processes” list.

Normally, you should at least see the process for JConsole itself:

If you do not see any process in the list, not even JConsole’s, then you probably have a permission issue. Let’s see how can that happen.

When you are running a JVM, it generates a log file for each of your JVM processes. These log files contain performance related information, and are by default stored in a folder called hsperfdata_yourusername under your operating system’s temp folder.

JConsole is using these log files, to show you the list of local processes. So if the log files do not exist, you will see an empty list under “Local Processes”. The reason why there are no log files for your processes could be, that the JVM does not have enough permissions to create them.

The easiest solution to this is to just delete this log folder and let the JVM recreate it with the correct permissions.

To find it in it’s default location on Windows, you can just check the contents of your TMP environment variable:

> echo %TMP%
C:\Users\Username\AppData\Local\Temp

Look for a folder called hsperfdata_yourusername in this temp diretory and simply delete it.

Relaunch JConsole and your applications that need monitoring, and you should now see your local processes.