How to Capture a Heap Dump from a Running JVM How to Capture a Heap Dump from a Running JVM elasticsearch elasticsearch

How to Capture a Heap Dump from a Running JVM


You need to make the directory you will write to, writable as the user which will do the writing, or you can use a directory every user can write to e.g.

sudo -u elasticsearch jmap -dump:format=b,file=/tmp/es-heap.hprof {processID}


The solution is to run jmap as root, but ensure the the file is writtable by the Java application. Think that jmap sends the dump command to the java application, the but dump is run inside it

sudo jmap -dump:format=b,file=/path/to/writable/directory/by/elastic/user/heap.hprof {processID}

That's it