Programmatically get heap info using jmx with java 5

I know to use jconsole to join a java process to get memory information. In particular, I get information about various memory pools programmatically, so I can bind it to a monitoring application.

Thanks!

+5
source share
2 answers

Thanks to the uterus - I did it mainly :-)

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;

}
+3
source

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

+2
source

All Articles