Back to index

munin  2.0.1
MemoryAllocatedTotal.java
Go to the documentation of this file.
00001 package org.munin.plugin.jmx;
00002 
00003 import java.lang.management.ManagementFactory;
00004 import java.lang.management.MemoryMXBean;
00005 import java.lang.management.MemoryUsage;
00006 
00007 import org.munin.plugin.jmx.AbstractAnnotationGraphsProvider.Graph;
00008 
00009 @Graph(title = "Allocated Memory", vlabel = "bytes", args = "--base 1024 -l 0", info="The sum of heap and non-heap memory currently used by the Java virtual machine.")
00010 public class MemoryAllocatedTotal extends AbstractMemoryUsageProvider {
00011        public MemoryAllocatedTotal(Config config) {
00012               super(config);
00013        }
00014 
00015        @Override
00016        protected void prepareValues() throws Exception {
00017               MemoryMXBean memoryMXBean = ManagementFactory.newPlatformMXBeanProxy(getConnection(),
00018                             ManagementFactory.MEMORY_MXBEAN_NAME, MemoryMXBean.class);
00019               MemoryUsage heap = memoryMXBean.getHeapMemoryUsage();
00020               MemoryUsage nonHeap = memoryMXBean.getNonHeapMemoryUsage();
00021               long totalInit = heap.getInit()+nonHeap.getInit();
00022               long totalUsed = heap.getUsed() + nonHeap.getUsed();
00023               long totalCommitted = heap.getCommitted()+nonHeap.getCommitted();
00024               long totalMax = heap.getMax()+nonHeap.getMax();
00025               memoryUsage = new MemoryUsage(totalInit, totalUsed, totalCommitted, totalMax);
00026        }
00027 
00028        public static void main(String args[]) {
00029               runGraph(args);
00030        }
00031 }