Back to index

munin  2.0.1
ThreadsHistorical.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.ThreadMXBean;
00006 
00007 import org.munin.plugin.jmx.AbstractAnnotationGraphsProvider.Graph;
00008 
00009 @Graph(title = "Thread Totals", vlabel = "threads", info = "Returns the peak live thread count and the total number of threads started since the Java virtual machine started.")
00010 public class ThreadsHistorical extends AbstractAnnotationGraphsProvider {
00011 
00012        private ThreadMXBean threadMXBean;
00013 
00014        public ThreadsHistorical(Config config) {
00015               super(config);
00016        }
00017 
00018        @Override
00019        protected void prepareValues() throws Exception {
00020               threadMXBean = ManagementFactory.newPlatformMXBeanProxy(
00021                             getConnection(), ManagementFactory.THREAD_MXBEAN_NAME,
00022                             ThreadMXBean.class);
00023        }
00024 
00025        @Field(info = "Maximum number of live threads since the JVM started or peak was reset.")
00026        public int threadsPeak() throws IOException {
00027               return threadMXBean.getPeakThreadCount();
00028        }
00029 
00030        @Field(type = "DERIVE", min = 0, info = "Number of threads created and started.")
00031        public long threadsStarted() throws IOException {
00032               // returning the total with type DERIVED means we get a nice
00033               // "number of threads started over time" graph
00034               return threadMXBean.getTotalStartedThreadCount();
00035        }
00036 
00037        public static void main(String args[]) {
00038               runGraph(args);
00039        }
00040 }