How to get heap dump from a remote server jvm?

11,786

Solution 1

You can use JMX to connect to the remote application server (it should be enabled in advance) and use the HotSpotDiagnostic MBean which allows taking a heap dump.
You can use JConsole or VisualVM for invoking the MBean operation.
This post by Mike Haller describes how to use this method with JVisualVM.

Solution 2

Since its a *-nix system, and if you have the necessary privieleges, then it would be easy to connect to using SSH protocol:

  • Connect to the remote machine:

    ssh user@remote-machine-ip-address
    
  • Enter the user password once prompted for it (it should be the one for the user on the remote machine and not your current system user).

  • Generate your heap dump using the jmap utility (JDK binaries path should be availble into your system PATH variable or use a full path to it):

    jmap -dump:format=b,file=cheap.bin <pid>
    

Solution 3

There are three steps:

  1. ssh to your server

ssh <your_user_name>@<remote_ip>

  1. jmap to trigger memory dump

jmap -dump:format=b,file=<your_file_name> <your_jvm_pid>

  1. visualize the heap by jhat (here 512m is the size limit, you can set it depends on the leak's file size, like -J-Xmx2g)

jhat -J-Xmx512m <your_file_name>

jhat -port 7401 <your_file_name>

I write a blog to help analyze performance issue: Performance Optimization

Solution 4

I've used Visual VM successfully for thread dumps and heap dumps, however, you don't list your JAVA version?

JAVA Visual VM is no longer shipped with JAVA, but can still be downloaded here and it's still being maintained. They just did a new minor release: October 19, 2021: VisualVM 2.1.1 Released.

VisualVM has also been distributed in Oracle JDK 6~8 as Java VisualVM. It has been discontinued in Oracle JDK 9.

Here are steps for connecting to the VM from Dzone, VisualVM: Monitoring Remote JVM Over SSH (JMX Or Not)

For other alternatives, the Baeldung JAVA site, which has great information and tutorials, has A Guide to Java Profilers.

Share:
11,786
Srisfti
Author by

Srisfti

Updated on June 07, 2022

Comments

  • Srisfti
    Srisfti almost 2 years

    How can I get aheap dump from a remote JVM which runs on linux with WL application server?

    When I run locally on a windows machine I know how to get a dump. But, how do I get a dump from the user acceptance test server? Thanks in advance.