View blogs | Login

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:
  1. Configuring the Java Server to enable JMX
  2. Configuring Putty to create an SSH tunnel
  3. 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 \ \ \ \ \ \
The above command line will enable JMX on port 9494.

Creating an SSH tunnel in putty

The following steps demonstrate configuration changes in Putty

  1. Load the session you use to connect to the remote machine
  2. Click Connections, SSH, Tunnels inside the Tree View on the left
  3. Enter an arbitrary value in Source Port, let's say that value is 9696
  4. Select Dynamic and click Add
  5. This will create a SOCKS port
  6. Save the session and connect to the remote host

Running VisualVM

  1. Start VisualVM
  2. Click Tools, Options
  3. Select the Network Tab
  4. Special localhost for SOCKS Proxy and put 9696 for Port. Click Ok
  5. Now create a connection to a remote machine.
  6. Right click on the newly added host name and select Add JMX connection...
  7. 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
  8. You should now be able to connect VisualVM to a Java process running on a remote machine

Created on: Mar 6, 2017
Last updated on: Jan 22, 2022


Your email address will not be published.


Social Media

Powered by