Enable Tomcat JMX

If you need to obtain server statistical data from Tomcat, you probably have to get it via Tomcat JMX. It’s pretty straight-forward to take a glance of what the current Tomcat server status with the JMX func by Tomcat.

Tomcat provides detail instruction here:https://tomcat.apache.org/tomcat-7.0-doc/monitoring.html#Enabling_JMX_Remote

Very simple.

Add parameter in setenv.sh to enable JMX.
Add it in CATALINA_OPTS
(Assume we use port number 9999)

CATALINA_OPTS="-Dcom.sun.management.jmxremote
  -Dcom.sun.management.jmxremote.port=9999
  -Dcom.sun.management.jmxremote.ssl=false
  -Dcom.sun.management.jmxremote.authenticate=false"

If we need authentication, change it to

CATALINA_OPTS="-Dcom.sun.management.jmxremote
  -Dcom.sun.management.jmxremote.port=9999
  -Dcom.sun.management.jmxremote.ssl=false
  -Dcom.sun.management.jmxremote.authenticate=true
  -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access
  -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password"

Notice. The directory of jmxremote.access and jmxremote.password may need absolute path if Tomcat fails to locate the file.

Here we create jmxremote.access file

monitorRole readonly
controlRole readwrite

Create jmxremote.password file

monitorRole abc123
controlRole xyz789

The jmxremote.password file must be set to readonly mode.

chmod 400 /path-to-it/jmxremote.password

oliver

Leave a Reply

Your email address will not be published. Required fields are marked *


*