-Dcom.sun.management.jmxremote
`-Dcom.sun.management.jmxremote.port=9910`
`-Dcom.sun.management.jmxremote.rmi.port=9910`
`-Dcom.sun.management.jmxremote.ssl=false`
`-Dcom.sun.management.jmxremote.authenticate=false`
`-Djava.rmi.server.hostname=localhost`
sudo ss -ntlp | grep java
Output will be something like this -

It should show the JMX process running on port **9910** along with other Java processes
1. Now, forward everything from local port 9910 to [**localhost:9910](<http://localhost:9910>)** on instance. Replace the ip according to the instance you want to monitor.
****`ssh -i <your pem file> -L 9910:localhost:9910 [[email protected]](<mailto:[email protected]>)`
Go to VisualVM. Right click the Local icon and select the “Add JMX Connection” option. Set the Connection field as localhost:9910
as shown below.
This connects us to desired ec2 instance server via the SSH tunnel running on localhost
port 9910
.