Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I need to monitor JVM Metaspace usage

Tags:

java

I need to monitor JVM Metaspace usage. Can you help me please with the following things?

How can I find the metaspace size used ?

Using the following commands I found the maxmetaspace and the min metaspace :

jmap -heap `ps -ef | grep java | grep -v grep | awk '{print $2}'` | grep -i Metaspace

MetaspaceSize = 21807104 (20.796875MB)
MaxMetaspaceSize = 1073741824 (1024.0MB)

but how can I find what is the value of memory used right now ?

like image 397
a.serghei Avatar asked Nov 20 '15 10:11

a.serghei


2 Answers

You can use the MemoryPoolMXBean.

List<MemoryPoolMXBean> memPool = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean p : memPool)
{
    if ("Metaspace".equals(p.getName()) 
    {
       ... here you have the memory pool mx bean with information about he metaspace
    }
}
like image 158
Uli Avatar answered Nov 04 '22 00:11

Uli


I use jstat -gcutil <pid> | awk '{print($5)}' that prints the Metaspace utilization as a percentage of the space's current capacity.

there are further options for jstat, explained here:

http://docs.oracle.com/javase/8/docs/technotes/tools/unix/jstat.html

like image 37
Paolo Franzini Avatar answered Nov 04 '22 00:11

Paolo Franzini