Is there any command line tool for monitoring the heap size usage of Java in CentOS?
Use jps
and jstack
to learn more about Java processes. jstat
can also be useful for Java statistics monitoring.
cd /opt/www/java/jdk/bin/
# jmap -heap <JAVA_PID>
-
had an error using it: "Cannot connect to core dump or remote debug server. Use jhsdb jmap instead."
jhsdb jmap --heap --pid xxxx
did the trick – Tom Jul 26 '19 at 10:21
jvmtop is a command-line tool which provides a live-view at several metrics, including heap.
Example output of the VM overview mode:
JvmTop 0.3 alpha (expect bugs) amd64 8 cpus, Linux 2.6.32-27, load avg 0.12
http://code.google.com/p/jvmtop
PID MAIN-CLASS HPCUR HPMAX NHCUR NHMAX CPU GC VM USERNAME #T DL
3370 rapperSimpleApp 165m 455m 109m 176m 0.12% 0.00% S6U37 web 21
11272 ver.resin.Resin [ERROR: Could not attach to VM]
27338 WatchdogManager 11m 28m 23m 130m 0.00% 0.00% S6U37 web 31
19187 m.jvmtop.JvmTop 20m 3544m 13m 130m 0.93% 0.47% S6U37 web 20
16733 artup.Bootstrap 159m 455m 166m 304m 0.12% 0.00% S6U37 web 46
-
-
@akirekadu There are many reasons. The most common ones are incompatible JDKs between jvmtop and the target jvm or insufficient/denied permissions. See FAQ for details. – MRalwasser Apr 29 '16 at 12:49
-
Only Java 9:
/usr/local/openjdk-11 seems to be no JDK!
But: github.com/patric-r/jvmtop/issues/109#issuecomment-622044148 :D – uav Apr 30 '20 at 19:31
You probably want to analyse the memory usage.
GCView might help you visualize what the GC-log shows.
If you already enabled the gc-log you could just use tail -f
on that log.
Try this it worked in ubuntu and redhat:
java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'
For windows:
java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize ThreadStackSize"
For mac
java -XX:+PrintFlagsFinal -version | grep -iE 'heapsize|permsize|threadstacksize'
The output of all this commands resembles the output below:
uintx InitialHeapSize := 20655360 {product} uintx MaxHeapSize := 331350016 {product} uintx PermSize = 21757952 {pd product} uintx MaxPermSize = 85983232 {pd product} intx ThreadStackSize = 1024 {pd product}
java version "1.7.0_05" Java(TM) SE Runtime Environment (build 1.7.0_05-b05) Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)
To find the size in MB divide the value with (1024*1024)
For monitoring the live heap memory usage use jconsole.
you can check this tool as well https://github.com/TeoGia/jotun
its a wrapper of jstat and outputs heap and RAM usage in json format