Programatically get heap info using jmx with java 5

狂风中的少年 提交于 2019-11-29 03:55:29

问题


I am aware of using jconsole to attach to a java process to get memory information. Specifically I'm after getting information on the various memory pools programatically so I can tie it to a monitoring application.

Thanks!


回答1:


Thanks mattk - I wound up doing basically this :-)

List memBeans = ManagementFactory.getMemoryPoolMXBeans();           
for (Iterator i = memBeans.iterator(); i.hasNext(); ) {

    MemoryPoolMXBean mpool = (MemoryPoolMXBean)i.next();
    MemoryUsage usage = mpool.getUsage();

    String name = mpool.getName();      
    float init = usage.getInit()/1000;
    float used = usage.getUsed()/1000;
    float committed = usage.getCommitted()/1000;
    float max = usage.getMax()/1000;
    float pctUsed = (used / max)*100;
    float pctCommitted = (committed / max)*100;

}



回答2:


Check out java.lang.management.MemoryPoolMXBean and related classes.



来源:https://stackoverflow.com/questions/462677/programatically-get-heap-info-using-jmx-with-java-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!