Monday, 9 June 2014

Enabling JMX in Tomcat

Any Java program can be monitored using Jconsole. Jconsole is an user interface which comes by default with any JDK package, you just need to type jconsole on your terminal and it will show you the interface. Jconsole works along with JMX, which has to be enabled in the respective java program or JVM.

How to enable JMX in tomcat?

You to enable these variables while starting of the JVM. In tomcat you can simple enable them by using CATALINA_OPTS variable in file in bin folder of tomcat.{port to access}
-Djava.rmi.server.hostname={optional, allow what ip to access this Tomcat}
export CATALINA_OPTS="$CATALINA_OPTS -Djava.rmi.server.hostname="

To know more details about variables, you can check here,

After changing this, start the tomcat and then run jconsole from anywhere and connect using
"IP:port", if authentication is enable, enter the credentials also. Now you can see all the JVM stuff, threads, memory usages, CPU usages, GCs performed etc.