Running VisualVM over SSH-Tunnel using Putty
Occasionally, I have to monitor a running process at a client's end through VisualVM. Enabling JMX, which is used by VisualVM, requires an additional TCP/IP port through the firewall. Most of the time it is an act of congress to get the network folks to open necessary TCP/IP ports allowing to monitor through JMX. Therefore, an alternate mechanism is required.
In this blog I will demonstrate how to monitor a Java server process using VisualVM, provided you have SSH access through Putty. I am assuming the following is true:
- Server is running on JDK 1.8 on a Linux machine that is across the Internet
- You have SSH access to the remote machine
- VisualVM is installed on your Windows machine
- Putty is installed and configured
Making everything work is a 3-step process:
- Configuring the Java Server to enable JMX
- Configuring Putty to create an SSH tunnel
- Configuring VisualVM to use this SSH tunnel
Configuring the Java process
Before you can use JMX, you will have to start the Java process using the following additional command lines
java -server -Dcom.sun.management.jmxremote \
The above command line will enable JMX on port 9494.
Creating an SSH tunnel in putty
The following steps demonstrate configuration changes in Putty
- Load the session you use to connect to the remote machine
- Click Connections, SSH, Tunnels inside the Tree View on the left
- Enter an arbitrary value in Source Port, let's say that value is 9696
- Select Dynamic and click Add
- This will create a SOCKS port
- Save the session and connect to the remote host
- Start VisualVM
- Click Tools, Options
- Select the Network Tab
- Special localhost for SOCKS Proxy and put 9696 for Port. Click Ok
- Now create a connection to a remote machine.
- Right click on the newly added host name and select Add JMX connection...
- Specify 9494 for the port number at the end of the host name. This port number should match with the JMX port number in step # 1
- You should now be able to connect VisualVM to a Java process running on a remote machine
||Mar 6, 2017
|Last updated on:
||Jun 24, 2021
LEAVE A COMMENT
Your email address will not be published.