Back to index

munin  2.0.1
GCCountGet.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.GarbageCollectorMXBean;
00005 import java.lang.management.ManagementFactory;
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 GCCountGet {
00014 
00015        private ArrayList<GarbageCollectorMXBean> gcmbeans;
00016        private String[] GCresult = new String[2];
00017        private MBeanServerConnection connection;
00018 
00019        public GCCountGet(MBeanServerConnection connection) {
00020               this.connection = connection;
00021        }
00022 
00023        public String[] GC() throws IOException, MalformedObjectNameException {
00024               ObjectName gcName = null;
00025 
00026               gcName = new ObjectName(
00027                             ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*");
00028 
00029               Set<ObjectName> mbeans = connection.queryNames(gcName, null);
00030               if (mbeans != null) {
00031                      gcmbeans = new ArrayList<GarbageCollectorMXBean>();
00032                      for (ObjectName objName : mbeans) {
00033                             GarbageCollectorMXBean gc = ManagementFactory
00034                                           .newPlatformMXBeanProxy(connection, objName
00035                                                         .getCanonicalName(),
00036                                                         GarbageCollectorMXBean.class);
00037                             gcmbeans.add(gc);
00038                      }
00039               }
00040 
00041               int i = 0;
00042               for (GarbageCollectorMXBean gc : gcmbeans) {
00043                      GCresult[i++] = gc.getCollectionCount() + "";
00044               }
00045               return GCresult;
00046        }
00047 }