Back to index

munin  2.0.1
AbstractMemoryUsageProvider.java
Go to the documentation of this file.
00001 package org.munin.plugin.jmx;
00002 
00003 import java.lang.management.MemoryPoolMXBean;
00004 import java.lang.management.MemoryUsage;
00005 
00006 public abstract class AbstractMemoryUsageProvider extends
00007               AbstractAnnotationGraphsProvider {
00008        
00009        protected MemoryUsage memoryUsage;
00010 
00011        protected AbstractMemoryUsageProvider(Config config) {
00012               super(config);
00013        }
00014 
00015        @Override
00016        protected abstract void prepareValues() throws Exception;
00017 
00018        @Field(info = "The maximum amount of memory (in bytes) that can be used for memory management.", draw = "AREA", colour = "ccff00", position = 1)
00019        public long max() {
00020               return (memoryUsage == null ? -1 : memoryUsage.getMax());
00021        }
00022 
00023        @Field(info = "The amount of memory (in bytes) that is guaranteed to be available for use by the Java virtual machine.", draw = "LINE2", colour = "0033ff", position = 2)
00024        public long committed() {
00025               return (memoryUsage == null ? -1 : memoryUsage.getCommitted());
00026        }
00027 
00028        @Field(info = "The initial amount of memory (in bytes) that the Java virtual machine requests from the operating system for memory management during startup.", position = 3)
00029        public long init() {
00030               return (memoryUsage == null ? -1 : memoryUsage.getInit());
00031        }
00032 
00033        @Field(info = "represents the amount of memory currently used (in bytes).", draw = "LINE3", colour = "33cc00", position = 4)
00034        public long used() {
00035               return (memoryUsage == null ? -1 : memoryUsage.getUsed());
00036        }
00037 
00038        protected void prepareMemoryUsage(MemoryPoolMXBean memoryPool, UsageType usageType) {
00039               switch (usageType) {
00040               case USAGE:
00041                      memoryUsage = memoryPool.getUsage();
00042                      break;
00043               case POST_GC:
00044                      memoryUsage = memoryPool.getCollectionUsage();
00045                      break;
00046               case PEAK:
00047                      memoryUsage = memoryPool.getPeakUsage();
00048                      break;
00049               default:
00050                      throw new IllegalArgumentException("Unknown UsageType: "
00051                                    + usageType);
00052               }
00053        }
00054 
00055        public enum UsageType {
00056               USAGE, POST_GC, PEAK,
00057        }
00058 }
00059