我需要监视JVM Metaspace使用情况

a.s*_*hei 5 java

我需要监视JVM Metaspace使用情况。您可以在以下方面帮我吗?

如何找到使用的元空间大小?

使用以下命令,我找到了maxmetaspace和min元空间:

jmap -heap `ps -ef | grep java | grep -v grep | awk '{print $2}'` | grep -i Metaspace
Run Code Online (Sandbox Code Playgroud)

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

但是如何找到当前使用的内存的价值呢?

Uli*_*Uli 4

您可以使用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
    }
}
Run Code Online (Sandbox Code Playgroud)