jstat
jstat (Java Virtual Machine Statistics Monitoring Tool) is a console tool that displays performance statistics for a JVM.
The –gcutil option identifies whether the JVM is spending a lot of time garbage collecting due to low memory. For example, the following command attaches to process 21891 and takes 7 samples at 250 millisecond intervals:
jstat -gcutil 21891 250 7 S0 S1 E O M CCS YGC YGCT FGC FGCT GCT 0.00 97.02 70.31 66.80 95.52 89.14 7 0.300 0 0.000 0.300 0.00 97.02 86.23 66.80 95.52 89.14 7 0.300 0 0.000 0.300 0.00 97.02 96.53 66.80 95.52 89.14 7 0.300 0 0.000 0.300 91.03 0.00 1.98 68.19 95.89 91.24 8 0.378 0 0.000 0.378 91.03 0.00 15.82 68.19 95.89 91.24 8 0.378 0 0.000 0.378 91.03 0.00 17.80 68.19 95.89 91.24 8 0.378 0 0.000 0.378 91.03 0.00 17.80 68.19 95.89 91.24 8 0.378 0 0.000 0.378
FGC (the number of full GC events) is an indicator of how busy the JVM is doing garbage collection. If this number increases quickly (for example, every 15 or 30 seconds or more frequently), it indicates memory issues.
The above output also indicates the Eden (E), Old (O) and Metaspace (M) memory % utilization.
For more information, see https://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html.