I run JVisualVM (Windows XP, Sun Java 1.6.0.13, 32 bit client VM) to monitor a distant application (Linux, Sun Java 1.6.0.07, 64 bit server VM). Before starting the actual remote application, I launch on the remote machine jstatd
using an all access policy:
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
Then I start the actual app using the command line
java -Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=3333
compileTest.Main
From the client machine, I can see the distant app and monitor it. I can also make a thread dump etc. Unfortunately, the heap-dump button is grayed out.
How can I obtain a heap-dump from a remotely monitored application using JVisualVM?
I tried using jConsole. With jConsole it is possible to make a distant heap dump using the com.sun.management.HotSpotDiagnostic dumpHeap operation. I want the dump to be transferred to the client side and analyzed using the tools provided by JVisualVM. How can I do this?
There is a way to do it!
- rmiregistry -J-Xbootclasspath/p:$JAVA_HOME/lib/sa-jdi.jar ( this uses port 1099)
- start 'jsadebugd' on the machine in which application is running: jsadebugd & (pid of JVM)
On remote machine use following jmap -dump:file= :1099
jhat
The above will start a web application at port 7000
All the above tools are part of JDK 1.6
All the best!
Unfortunately there isn't an automated way to do this. You'll have to run jmap manually on the Linux server to dump the heap of your JVM and then copy the resultant heap dump to your local machine running JVisualVM and use File|Load... to load the heap dump into JVisualVM for analysis.
Since 1.3, VisualVM support remote heap dumps:
Starting with VisualVM 1.3, you can now use the Heap Dump actions and buttons in the tool to take a heap dump of applications that are running remotely. When invoked, a dialog is displayed that enables you to specify the full path on the remote system where you want to dump the heap. After the heap dump is created, you need to manually copy the file to your local machine and use the Load action to open and analyze the file using VisualVM.
You cannot analyze the heap remotely. You could run visualvm on your server and export the x session to your local machine. You would have to have x11 installed on your server which many servers do not.
来源:https://stackoverflow.com/questions/726643/get-heap-dump-from-a-remote-application-in-java-using-jvisualvm