Back to index

munin  2.0.1
Threads.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 = "Threads", vlabel = "threads", info = "Shows the number of live threads including both daemon and non-daemon threads.")
00010 public class Threads extends AbstractAnnotationGraphsProvider {
00011 
00012        private ThreadMXBean threadMXBean;
00013        
00014        public Threads(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="number of live threads in total", draw = "AREA", position=1)
00026        public int threads() throws IOException {
00027               return threadMXBean.getThreadCount();
00028        }
00029 
00030        @Field(info="number of live daemon threads", position = 2)
00031        public int threadsDaemon() throws IOException {
00032               return threadMXBean.getDaemonThreadCount();
00033        }
00034 
00035        public static void main(String args[]) {
00036               runGraph(args);
00037        }
00038 }