001/* 002 * Copyright 2012 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.runtime.plugins.admin.jvmstatus.monitoring.sample; 017 018import java.io.IOException; 019import java.lang.management.ManagementFactory; 020import java.util.HashMap; 021import java.util.Map; 022 023import org.rrd4j.DsType; 024import org.rrd4j.core.RrdDef; 025import org.rrd4j.core.Sample; 026 027import org.ametys.runtime.plugins.admin.jvmstatus.monitoring.SampleManager; 028 029/** 030 * {@link SampleManager} for collecting the uptime of the JVM. 031 */ 032public class UptimeSampleManager extends AbstractSampleManager 033{ 034 @Override 035 protected void _configureDatasources(RrdDef rrdDef) 036 { 037 _registerDatasources(rrdDef, "uptime", DsType.GAUGE, 0, Double.NaN); 038 } 039 040 @Override 041 protected Map<String, Object> _internalCollect(Sample sample) throws IOException 042 { 043 Map<String, Object> result = new HashMap<>(); 044 long uptime = ManagementFactory.getRuntimeMXBean().getUptime(); 045 sample.setValue("uptime", uptime); 046 result.put("uptime", uptime); 047 return result; 048 } 049 050 @Override 051 protected String _getGraphTitle() 052 { 053 return "Uptime"; 054 } 055}