Monitor Tomcat with JMX and jConsole
This tutorial shows how to monitor Tomcat with JMX via jConsole. Monitoring is a key aspect for developers or system administrators. Looking inside a running server, obtaining some statistics like: Heap / Non-heap memory utilization, CPU Usage or active threads, etc. This information is of great value, when designing and maintaining software. You are also able to reconfigure some aspects of an application via MBeans.
Key Features for monitoring Java Applications on Tomcat
- Reconfigure your server on the fly via MBeans.
- Monitor application availability and performance monitoring.
- Isolate long running threads.
- Monitor Server Resources
- Heap / Non-heap memory utilization.
- Live Threads inspection.
- JVM Memory Spaces.
- Garbage Collection.
- CPU Utilization.
- Disk I/O
- Server Up-Time / Environment Details.
Enable JMX in Tomcat
You can enable JMX by passing the correct Java properties when tomcat starts. You’ll need to create a setenv.sh
or setenv.bat
file, depending on your operating system and pass the parameters in the CATALINA_OPTS
environment variable.
For windows you’ll need to create a setenv.bat
file and place it in the %TOMCAT_HOME%/bin/
folder.
set CATALINA_OPTS="%CATALINA_OPTS%
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=localhost";
For linux/unix/mac os x you’ll need to create a setenv.sh
file and place it in the %TOMCAT_HOME%/bin/
folder.
export CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=localhost";
Warning: this configuration is for development only. When you enable JMX in production, make sure you enable password security over a secure SSL/TLS connection.
Start Tomcat and Monitor with JMX via jConsole
Previously, we configured JMX on Tomcat. With this configuration you’ll be able to access the JMX console using localhost:9999
. When your paths are configured correctly, you can simply start jconsole in your command promt or terminal. If not, you can start the jConsole by executing the %JAVA_HOME%/bin/jconsole
. When the jConsole is started, you can connect to tomcat using the configured port.
When you’re connected to the jConsole, you can monitor tomcat.