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 ?
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
}
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With