16

Is there any command line tool for monitoring the heap size usage of Java in CentOS?

6 Answers 6

8

Use jps and jstack to learn more about Java processes. jstat can also be useful for Java statistics monitoring.

6
cd /opt/www/java/jdk/bin/

# jmap -heap <JAVA_PID>
1
  • had an error using it: "Cannot connect to core dump or remote debug server. Use jhsdb jmap instead." jhsdb jmap --heap --pid xxxxdid the trick
    – Tom
    Jul 26, 2019 at 10:21
5

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
3
  • why there is an error for process 11272?
    – akirekadu
    Apr 28, 2016 at 22:35
  • @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, 2016 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, 2020 at 19:31
1

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.

1

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.

Jconsole Screenshot

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .