Back to index

munin  2.0.1
Uptime.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.RuntimeMXBean;
00006 
00007 import org.munin.plugin.jmx.AbstractAnnotationGraphsProvider.Graph;
00008 
00009 @Graph(title = "Uptime", vlabel = "days", info = "Uptime of the Java virtual machine in days.")
00010 public class Uptime extends AbstractAnnotationGraphsProvider {
00011 
00012        private static final double MILLISECONDS_PER_DAY = 1000 * 60 * 60 * 24d;
00013 
00014        public Uptime(Config config) {
00015               super(config);
00016        }
00017 
00018        @Field
00019        public double uptime() throws IOException {
00020               RuntimeMXBean osmxbean = ManagementFactory.newPlatformMXBeanProxy(
00021                             getConnection(), ManagementFactory.RUNTIME_MXBEAN_NAME,
00022                             RuntimeMXBean.class);
00023 
00024               return osmxbean.getUptime() / MILLISECONDS_PER_DAY;
00025        }
00026 
00027        public static void main(String args[]) {
00028               runGraph(args);
00029        }
00030 
00031 }