Java HotSpot VM Command-Line HeapDumpPath option use hostname for resulting .hprof



Summary: Id like to alter the way .hprofs are named when automatically created to incorporate machine’s hostname + process PID

Long version: According to documentation (https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/clopts001.html) you can pass an option to the VM to create heapdumps under certain conditions (HeapDumpOnOutOfMemoryError), and can further customize this behavior by specifying a different path for the resulting .hprof file. You can change the name/path. What I would like to know is if its possible to make this option (HeapDumpPath) incorporate the hostname+PID to have uniquely named .hprofs (to be saved in a centralized location, but thats another scope). Could it be done? Can HeapDumpPath accept a parameter to get the hostname?

Answer

Managed to do it just by using the Windows Environment Variable COMPUTERNAME in the wrapper.conf file for that particular Java VM. The full line is:

wrapper.java.additional.32=-XX:HeapDumpPath=./%COMPUTERNAME%.hprof



Source: stackoverflow