Back to index

munin  2.0.1
GetMemoryPoolThresholdCount.java
Go to the documentation of this file.
00001 package org.munin.plugin.jmx;
00002 
00003 import java.io.IOException;
00004 import java.lang.management.ManagementFactory;
00005 import java.lang.management.MemoryPoolMXBean;
00006 import java.util.ArrayList;
00007 import java.util.Set;
00008 
00009 import javax.management.MBeanServerConnection;
00010 import javax.management.MalformedObjectNameException;
00011 import javax.management.ObjectName;
00012 
00013 class GetMemoryPoolThresholdCount {
00014        private ArrayList<MemoryPoolMXBean> gcmbeans;
00015        private long[] GCresult = new long[4];
00016        private MBeanServerConnection connection;
00017 
00018        public GetMemoryPoolThresholdCount(MBeanServerConnection connection) {
00019               this.connection = connection;
00020        }
00021 
00022        public long[] GC() throws IOException, MalformedObjectNameException {
00023               ObjectName gcName = null;
00024 
00025               gcName = new ObjectName(
00026                             ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*");
00027 
00028               Set<ObjectName> mbeans = connection.queryNames(gcName, null);
00029               if (mbeans != null) {
00030                      gcmbeans = new ArrayList<MemoryPoolMXBean>();
00031                      for (ObjectName objName : mbeans) {
00032                             MemoryPoolMXBean gc = ManagementFactory.newPlatformMXBeanProxy(
00033                                           connection, objName.getCanonicalName(),
00034                                           MemoryPoolMXBean.class);
00035                             gcmbeans.add(gc);
00036                      }
00037               }
00038 
00039               int i = 0;
00040               GCresult[i++] = gcmbeans.get(0).getCollectionUsageThresholdCount();
00041               GCresult[i++] = gcmbeans.get(1).getCollectionUsageThresholdCount();
00042               GCresult[i++] = gcmbeans.get(3).getCollectionUsageThresholdCount();
00043               GCresult[i++] = gcmbeans.get(4).getCollectionUsageThresholdCount();
00044 
00045               return GCresult;
00046        }
00047 }