Using JMX to analyse a Java Virtual Machine (JVM) within a local or remote docker image. The example below explores how to analyse a Tomcat Server (version 7) running in a docker instance using Oracle JRockit Mission Control (JMC)
Your JRockit Mission Control is here
- OSX : “/Library/Java/JavaVirtualMachines/{JDK}/Contents/Home/bin/”
- Windows: “JDK_HOME/bin/”
Step-by-step guide
Add the steps involved:
- Determine your docker machines IP, for example on our machine we did
-
Do `docker-machine active` to see the active machines
-
On my machine this returned `default` as the machine name
-
-
Do `docker-machine ip default` to see the IP of the machine named ‘default`
-
On my machine this returned `192.168.99.100`
-
-
- Create a setenv.sh script with the JMX options
- Set the `CATALINA_OPTS` env variable as shown below
- Set the “java.rmi.server.hostname” to the IP obtained in step (1.b) above
- Please note that we are not using SSL nor JMX Remote Authentication – so the config below is for DEV only
- Use the setenv.sh script within the tomcat runtime
- In your Dockerfile you can do
- `ADD setenv.sh /apache-tomcat-7.0.62/bin/setenv.sh` when using an Apache Tomcat image
- or `ADD setenv.sh /camunda/bin/setenv.sh` when using Camunda (embedded or standalone)
- You can add this at runtime as well using
- `-v ${PWD}/setenv.sh:/apache-tomcat-7.0.62/bin/setenv.sh`when using an Apache Tomcat image
- or `-v ${PWD}/setenv.sh:/camunda/bin/setenv.sh` when using Camunda (embedded or standalone)
- In your Dockerfile you can do
- Start the Docker container and map JMX ports
- To the `docker run` command add the following ports
- The JMX Remote and RMI Port `-p 1898:1898`
- and TCP Transport Port `-p 62911:62911`
- To the `docker run` command add the following ports
- Validate the Docker container is exposing the ports
- Do a `docker ps ` and example your image’s ports
- Do a `docker exec -i -t` and validate the contents of your setenv.sh file to confirm the CATALINA_OPTS are set
- NOT doing will throw you off if the setenv.sh is not copied! Simple exposing the Docker container ports does not mean the JVM allows JMX connections
- Example: Docker Exec command to view the contents of the file for apache-tomcat-7.0.62
- Run the JRockit Mission Control
- Comes with the JDK
- On a Mac you can find it here “/Library/Java/JavaVirtualMachines/{JDK}/Contents/Home/bin/” and the executable is called “jmc”
-
Add a Remote connection in JMC
- File – > Connect
- Provide the JMX Connection properties
- Host is the Docker Machine IP we obtained in Step 1 above
- Port is the JMX Remote Port, for example: 1898 in Step 2 above
- Name the Connection “Docker-<image-name>”
- Test the Connection
- Your JVM shows up in JRockit
- Start JMX Console and view JVM metrics
See more details on how to use the JRockit JVM tool here