16

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

Nikhil Mulley
  • 8,145
  • 32
  • 49
Mughil
  • 1,963
  • 4
  • 18
  • 23

6 Answers6

8

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

Kevin
  • 40,087
  • 16
  • 88
  • 112
Nikhil Mulley
  • 8,145
  • 32
  • 49
6
cd /opt/www/java/jdk/bin/

# jmap -heap <JAVA_PID>
jasonwryan
  • 71,734
  • 34
  • 193
  • 226
Anurag Sharma
  • 61
  • 1
  • 1
  • 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
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
MRalwasser
  • 211
  • 2
  • 6
  • why there is an error for process 11272? – akirekadu Apr 28 '16 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](https://github.com/patric-r/jvmtop/blob/master/doc/FAQ.md) for details. – MRalwasser Apr 29 '16 at 12:49
  • Only Java 9: `/usr/local/openjdk-11 seems to be no JDK!` But: https://github.com/patric-r/jvmtop/issues/109#issuecomment-622044148 :D – uav Apr 30 '20 at 19:31
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

padippist
  • 111
  • 3
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.

Nils
  • 18,202
  • 11
  • 46
  • 82
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