Back to index

munin  2.0.1
MemoryPoolUsageProvider.java
Go to the documentation of this file.
00001 package org.munin.plugin.jmx;
00002 
00003 import java.io.PrintWriter;
00004 import java.lang.management.ManagementFactory;
00005 import java.lang.management.MemoryPoolMXBean;
00006 
00007 import javax.management.ObjectName;
00008 
00009 public class MemoryPoolUsageProvider extends AbstractMemoryUsageProvider {
00010        private final ObjectName poolName;
00011        private final UsageType usageType;
00012 
00013        public MemoryPoolUsageProvider(final Config config, final ObjectName poolName,
00014                      final UsageType usageType) {
00015               super(config);
00016               this.poolName = poolName;
00017               this.usageType = usageType;
00018        }
00019 
00020        @Override
00021        /*
00022         * We need to write the graph config manually, since it's dynamic and can't
00023         * be specified in annotations.
00024         */
00025        protected void printGraphConfig(PrintWriter out) {
00026               String name = poolName.getKeyProperty("name");
00027               String usagePhrase = "";
00028               switch (usageType) {
00029               case POST_GC:
00030                      usagePhrase ="collection ";
00031                      break;
00032               case PEAK:
00033                      usagePhrase = "peak ";
00034                      break;
00035               }
00036               String graphTitle = "JVM (port " + config.getPort() + ") " + name + " Memory Pool " + usagePhrase + "usage";
00037               String graphVlabel = "bytes";
00038               String graphArgs = "--base 1024 -l 0";
00039               String graphInfo = usagePhrase + "memory usage of the " + name + " memory pool";
00040               
00041               printGraphConfig(out, graphTitle, graphVlabel, graphInfo, graphArgs, true, true);
00042        }
00043 
00044        @Override
00045        protected void prepareValues() throws Exception {
00046               MemoryPoolMXBean pool = ManagementFactory
00047                             .newPlatformMXBeanProxy(getConnection(),
00048                                           poolName.getCanonicalName(), MemoryPoolMXBean.class);
00049               prepareMemoryUsage(pool, usageType);
00050        }
00051 }