Java Heap Usage Monitoring JConsole has one single window that conveniently shows Heap Memory Usage, as seen at http://www.oracle.com/technetwork/java/javase/tooldescr-136044.html#gblfi Unfortunately, there's no simple command-line equivalent. The output of jmap is a little verbose, e.g., $ export JAVA_HOME=/u01/app/oracle/agent/core/12.1.0.2.0/jdk $ export PATH=$JAVA_HOME/bin:$PATH $ jconsole & $ jps 30216 JConsole 35470 TMMain 49669 Jps $ jmap -heap 35470 Attaching to process ID 35470, please wait... Debugger attached successfully. Server compiler detected. JVM version is 19.1-b02 using parallel threads in the new generation. using thread-local object allocation. Concurrent Mark-Sweep GC Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 536870912 (512.0MB) NewSize = 21757952 (20.75MB) MaxNewSize = 392560640 (374.375MB) OldSize = 65404928 (62.375MB) NewRatio = 7 SurvivorRatio = 8 PermSize = 21757952 (20.75MB) MaxPermSize = 100663296 (96.0MB) Heap Usage: New Generation (Eden + 1 Survivor Space): capacity = 19595264 (18.6875MB) used = 12259480 (11.691551208496094MB) free = 7335784 (6.995948791503906MB) 62.56348472773829% used Eden Space: capacity = 17432576 (16.625MB) used = 10109904 (9.641555786132812MB) free = 7322672 (6.9834442138671875MB) 57.9943205180921% used From Space: capacity = 2162688 (2.0625MB) used = 2149576 (2.0499954223632812MB) free = 13112 (0.01250457763671875MB) 99.39371744791667% used To Space: capacity = 2162688 (2.0625MB) used = 0 (0.0MB) free = 2162688 (2.0625MB) 0.0% used concurrent mark-sweep generation: capacity = 65404928 (62.375MB) used = 29821640 (28.44013214111328MB) free = 35583288 (33.93486785888672MB) 45.59540223024173% used Perm Generation: capacity = 83234816 (79.37890625MB) used = 51896416 (49.492279052734375MB) free = 31338400 (29.886627197265625MB) 62.34940917031642% used My goal is to find the numbers in the `jmap' output that match the value shown in Heap Memory Usage of JConsole, for the purpose of scripting and setting up cron jobs. After some tests, it appears that the "used" values under "New Generation", "From Space", and "concurrent mark-sweep generation" add up to the JConsole Heap Memory Usage. So the following command is constructed: $ jmap -heap 35470 2>&1 | egrep -A2 '^New|^From|^concurrent' | grep used | awk '{sum+=$3}END{print sum/1048576}' 35.6144 Note: In setting up a cron job, the pid has to be found through `pgrep', `jps', `ps -ef|grep ...' or other means. If the garbage collection (GC) algorithm is not "Concurrent Mark-Sweep GC" as shown in the above example, adjust the grep-pattern as needed. For example, with "PS Young Generation" algorithm, "Eden Space" used value should be counted (there's no "New Generation" that encompasses it). May 2016