JVisualVM is a great tool for monitoring JVM regarding memory issues, threads and GC … etc. There are two modes of communication between VisualVM and the JVM either over JMX or jstatd.

In this post I will only go through over JMX.

What I m trying to do

I will explain how to monitor a remote application through JMX by establishing an SSH tunnel.

Enviroment

Prerequisite

Basic Steps

  1. Prepare JAVA application
  2. Establish ssh tunnel to the remote machine
  3. Run and Configure JVisualVM

1. JAVA application

yourJavaCommand...  -Dcom.sun.management.jmxremote.ssl=false 
                    -Dcom.sun.management.jmxremote.authenticate=false 
                    -Dcom.sun.management.jmxremote.port=9010
                    -Dcom.sun.management.jmxremote.rmi.port=9011
                    -Djava.rmi.server.hostname=localhost
                    -Dcom.sun.management.jmxremote.local.only=false

Note : it’s important to set both ports jmx and rmi port

For more info regarding jmx connection, see Remote JMX Connections.

2. SSH TUNNEL

ssh -i yourPermissionFile.pem -l username 101.101.101.101 -L 9010:localhost:9010 -L 9011:localhost:9011

3. JVisualVM

run-VisualVM

configure-VisualVM