Following prior answers given, but had couple additional pieces to acknowledge:
- cannot sample memory remotely
- use X to run a local-to-jvm instance of VisualVM and export DISPLAY back to your workstation
there is some nasty issue with jdk_1.7.0_25 that causes at least in my case under CentOS an exception thrown trying to run jvisualvm or the downloaded VisualVM:
java.lang.NoClassDefFoundError: Could not initialize class sun.awt.SunToolkit
use the same user account to run both your target JVM (in my case Tomcat server) and your instnace of VisualVM
From prior answer, this was useful (thank you Morteza Shahriari Nia)
$ ssh -Y user@remotemachine
$ wget http://java.net/projects/visualvm/downloads/download/release135/visualvm_136.zip
$ unzip visualvm_136.zip
$ cd visualvm_136/bin
$ ./visualvm
Each time before you run "visualvm_136/bin/visualvm", get your X display back to your workstation you need to ...
- local machine: $ xhost +
- remote machine: $ export DISPLAY=your_workstation_ip:0.0
Once it starts up (and your target JVM is already running and your are same user account as per #4 above), you will see your target PID listed in the "Local" section of VisualVM.
I was able to use differing versions of jdk and still able to see memory sampler enabled - in my case the target Tomcat JVM was running jdk_1.7.0_25, whereas my VisualVM instance was earlier version jdk_1.7.0_04 (due to issue #3, had to use different version for VisualVM).
Hope that helps ...