List of usage examples for java.lang.management RuntimeMXBean getUptime
public long getUptime();
From source file:eu.openanalytics.rsb.component.SystemHealthResource.java
@GET @Path("/info") @Produces({ Constants.RSB_XML_CONTENT_TYPE, Constants.RSB_JSON_CONTENT_TYPE }) public NodeInformation getInfo(@Context final ServletContext sc) { final NodeInformation info = Util.REST_OBJECT_FACTORY.createNodeInformation(); info.setName(getConfiguration().getNodeName()); info.setHealthy(nodeHealthy.get());//from w ww.j av a 2 s . c o m info.setRsbVersion(getClass().getPackage().getImplementationVersion()); info.setServletContainerInfo(sc.getServerInfo()); final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); info.setOsLoadAverage(operatingSystemMXBean.getSystemLoadAverage()); final Runtime runtime = Runtime.getRuntime(); info.setJvmMaxMemory(runtime.maxMemory()); info.setJvmFreeMemory(runtime.freeMemory()); final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); final long uptimeMilliseconds = runtimeMXBean.getUptime(); info.setUptime(uptimeMilliseconds); info.setUptimeText(DurationFormatUtils.formatDurationWords(uptimeMilliseconds, true, true)); return info; }
From source file:org.alfresco.reporting.cron.ReportExecutionJob.java
public void executeImpl(AtomicBoolean running, JobExecutionContext context) throws JobExecutionException { // actually do what needs to be done // a cron job can only trigger // -all- ReportingContainers with same frequency // -all- ReprotingContainers no matter what frequency (all-all) final JobDataMap jobData = context.getJobDetail().getJobDataMap(); // can be null, then execute all frequencies final String frequency = jobData.getString("frequency"); if (logger.isDebugEnabled()) logger.debug("executeImpl starting with frequency " + frequency); int startupDelayMillis = 0; startupDelayMillis = Integer.parseInt(jobData.getString("startDelayMinutes")) * 60000; if (logger.isDebugEnabled()) logger.debug("executeImpl starting with delay " + startupDelayMillis); // wait system i starting RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); if (startupDelayMillis < rb.getUptime()) { // we are x minutes after startup of the repository, lets roll! AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>() { public Void doWork() { Action action = actionService.createAction(ReportRootExecuter.NAME); boolean canRun = false; // make true if run can be successful... if (frequency != null) { if ("hourly".equals(frequency)) { action.setParameterValue(ReportRootExecuter.PARAM_FREQUENCY, frequency); canRun = true;/*from ww w . j a va 2s. c o m*/ } // end hourly if ("daily".equals(frequency)) { action.setParameterValue(ReportRootExecuter.PARAM_FREQUENCY, frequency); canRun = true; } // end daily if ("weekly".equals(frequency)) { action.setParameterValue(ReportRootExecuter.PARAM_FREQUENCY, frequency); canRun = true; } // end weekly if ("monthly".equals(frequency)) { action.setParameterValue(ReportRootExecuter.PARAM_FREQUENCY, frequency); canRun = true; } // end monthly if (canRun) { if (logger.isDebugEnabled()) logger.debug("executeImpl: start running action " + frequency); actionService.executeAction(action, null); } else { logger.error( "executeImpl: Confguration mistake, cannot run. Frequency has no meaningful value: " + frequency); } } // end if frequency!=null else { action.setParameterValue(ReportRootExecuter.PARAM_FREQUENCY, "hourly"); actionService.executeAction(action, null); action.setParameterValue(ReportRootExecuter.PARAM_FREQUENCY, "daily"); actionService.executeAction(action, null); action.setParameterValue(ReportRootExecuter.PARAM_FREQUENCY, "weekly"); actionService.executeAction(action, null); action.setParameterValue(ReportRootExecuter.PARAM_FREQUENCY, "monthly"); actionService.executeAction(action, null); } return null; } // end doWork }, AuthenticationUtil.getSystemUserName()); } else { logger.info( "Hey relax! Its too early to work... Let the repository get up first... Aborting this run."); } }
From source file:com.eurelis.opencms.admin.systeminformation.CmsCPUThreadsClassesOverviewDialog.java
public static double getCPUUsage(HttpSession session) { OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); int availableProcessors = operatingSystemMXBean.getAvailableProcessors(); Long prevUpTime = (Long) session.getAttribute(PARAM_TIMESTAMP); Long prevProcessCpuTime = (Long) session.getAttribute(PARAM_PROCESS_CPU_TIME); double cpuUsage; operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); long upTime = runtimeMXBean.getUptime(); long processCpuTime = operatingSystemMXBean.getProcessCpuTime(); if (prevProcessCpuTime != null || prevUpTime != null) { long elapsedCpu = processCpuTime - prevProcessCpuTime.longValue(); long elapsedTime = upTime - prevUpTime.longValue(); cpuUsage = Math.min(99F, elapsedCpu / (elapsedTime * 10000F * availableProcessors)); } else {//www . jav a2 s .c o m cpuUsage = 0; } session.setAttribute(PARAM_PROCESS_CPU_TIME, processCpuTime); session.setAttribute(PARAM_TIMESTAMP, upTime); return cpuUsage; }
From source file:com.thoughtworks.go.server.service.support.ServerRuntimeInformationProvider.java
private void runtimeInfo(RuntimeMXBean runtimeMXBean, InformationStringBuilder builder) { builder.addSection("Runtime information"); builder.append(String.format("Name - %s\n", runtimeMXBean.getName())); long uptime = runtimeMXBean.getUptime(); long uptimeInSeconds = uptime / 1000; long numberOfHours = uptimeInSeconds / (60 * 60); long numberOfMinutes = (uptimeInSeconds / 60) - (numberOfHours * 60); long numberOfSeconds = uptimeInSeconds % 60; builder.append(String.format("Uptime - %s [About %s hours, %s minutes, %s seconds]\n", uptime, numberOfHours, numberOfMinutes, numberOfSeconds)); builder.append(String.format("Spec Name - %s\n", runtimeMXBean.getSpecName())); builder.append(String.format("Spec Vendor - %s\n", runtimeMXBean.getSpecVendor())); builder.append(String.format("Spec Version - %s\n", runtimeMXBean.getSpecVersion())); builder.addSubSection("Input Arguments") .append(asIndentedMultilineValues(runtimeMXBean.getInputArguments())); builder.addSubSection("System Properties") .append(asIndentedMultilineValues(runtimeMXBean.getSystemProperties())); builder.addSubSection("Classpath").append(prettyClassPath(runtimeMXBean.getClassPath())); builder.addSubSection("Boot Classpath").append(prettyClassPath(runtimeMXBean.getBootClassPath())); }
From source file:com.all.ultrapeer.UltrapeerMonitor.java
private double calculateCpuUsage() throws InterruptedException { OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); int numCpus = operatingSystemMXBean.getAvailableProcessors(); long prevUpTime = runtimeMXBean.getUptime(); long prevProcessCpuTime = operatingSystemMXBean.getProcessCpuTime(); Thread.sleep(500);/*w ww . j a v a 2 s . c o m*/ long upTime = runtimeMXBean.getUptime(); long processCpuTime = operatingSystemMXBean.getProcessCpuTime(); if (prevUpTime > 0L && upTime > prevUpTime) { long elapsedCpu = processCpuTime - prevProcessCpuTime; long elapsedTime = upTime - prevUpTime; return Math.min(99F, elapsedCpu / (elapsedTime * 10000F * numCpus)); } return 0.001; }
From source file:com.springsource.hq.plugin.tcserver.plugin.TomcatMeasurementPlugin.java
private long getJvmUptime(MBeanServerConnection connection) throws MetricUnreachableException { String upTimeQuery = "java.lang:type=Runtime"; RuntimeMXBean bean; try {/* w ww . j av a 2 s. co m*/ bean = getRuntimeMXBean(connection, upTimeQuery); } catch (IOException e) { throw new MetricUnreachableException("Error obtaining process UpTime:" + e.getMessage(), e); } return bean.getUptime(); }
From source file:com.eurelis.opencms.admin.systeminformation.CmsSystemInformationOverviewDialog.java
/** * Initializes the infos object.<p> *///from www . j ava 2 s .c o m protected void initInfosObject() { com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean(); java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean(); //JVM uptime Date date = new Date(runtimeBean.getUptime()); java.text.SimpleDateFormat simpleFormatH = new java.text.SimpleDateFormat("HH"); java.text.SimpleDateFormat simpleFormatM = new java.text.SimpleDateFormat("mm"); java.text.SimpleDateFormat simpleFormatS = new java.text.SimpleDateFormat("ss"); String jvmuptimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min " + simpleFormatS.format(date) + "s "; //JVM start time date = new Date(runtimeBean.getStartTime()); String jvmstarttimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min " + simpleFormatS.format(date) + "s "; //OpenCms runtime date = new Date(OpenCms.getSystemInfo().getRuntime()); String opencmsruntimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min " + simpleFormatS.format(date) + "s "; //OpenCms startup time date = new Date(OpenCms.getSystemInfo().getStartupTime()); String opencmsstartuptimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min " + simpleFormatS.format(date) + "s "; setOperatingSystem("" + osBean.getName()); setJavaVersion(System.getProperty("java.version")); setJvmUptime("" + jvmuptimestring); setJvmStarttime("" + jvmstarttimestring); setOpenCmsVersion(OpenCms.getSystemInfo().getVersionNumber()); setOpenCmsRuntime("" + opencmsruntimestring); setOpenCmsStartupTime("" + opencmsstartuptimestring); Object o; if (CmsStringUtil.isEmpty(getParamAction())) { o = new CmsAdminSettings(getSession()); } else { // this is not the initial call, get the job object from session o = getDialogObject(); } if (!(o instanceof CmsAdminSettings)) { // create a new history settings handler object m_adminSettings = new CmsAdminSettings(getSession()); } else { // reuse html import handler object stored in session m_adminSettings = (CmsAdminSettings) o; } }
From source file:net.risesoft.soa.asf.web.controller.SystemController.java
private List<SysInfo> getVMInfo() { List list = new ArrayList(); String group = "3. VM ?"; RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean(); list.add(new SysInfo("BootClassPath", rt.getBootClassPath(), group)); list.add(new SysInfo("ClassPath", rt.getClassPath(), group)); list.add(new SysInfo("LibraryPath", rt.getLibraryPath(), group)); list.add(new SysInfo("ManagementSpecVersion", rt.getManagementSpecVersion(), group)); list.add(new SysInfo("Name", rt.getName(), group)); list.add(new SysInfo("SpecName", rt.getSpecName(), group)); list.add(new SysInfo("SpecVendor", rt.getSpecVendor(), group)); list.add(new SysInfo("SpecVersion", rt.getSpecVersion(), group)); list.add(new SysInfo("VmName", rt.getVmName(), group)); list.add(new SysInfo("VmVendor", rt.getVmVendor(), group)); list.add(new SysInfo("VmVersion", rt.getVmVersion(), group)); list.add(new SysInfo("StartTime", DateFormat.getDateTimeInstance().format(new Date(rt.getStartTime())), group));//from ww w . j ava2 s .c o m list.add(new SysInfo("UpTime", this.helper.getUpTimeStr(rt.getUptime()), group)); list.add(new SysInfo("InputArguments", rt.getInputArguments(), group)); group = "6. ?"; Map<String, String> sysProps = rt.getSystemProperties(); for (Map.Entry entry : sysProps.entrySet()) { list.add(new SysInfo((String) entry.getKey(), entry.getValue(), group)); } Collections.sort(list, new Comparator() { public int compare(SystemController.SysInfo o1, SystemController.SysInfo o2) { String key1 = o1.getKey(); String key2 = o2.getKey(); return key1.compareToIgnoreCase(key2); } }); return list; }
From source file:com.evolveum.midpoint.gui.api.util.WebComponentUtil.java
public static double getSystemLoad() { com.sun.management.OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); int availableProcessors = operatingSystemMXBean.getAvailableProcessors(); long prevUpTime = runtimeMXBean.getUptime(); long prevProcessCpuTime = operatingSystemMXBean.getProcessCpuTime(); try {// ww w . jav a 2 s.co m Thread.sleep(150); } catch (Exception ignored) { // ignored } operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); long upTime = runtimeMXBean.getUptime(); long processCpuTime = operatingSystemMXBean.getProcessCpuTime(); long elapsedCpu = processCpuTime - prevProcessCpuTime; long elapsedTime = upTime - prevUpTime; double cpuUsage = Math.min(99F, elapsedCpu / (elapsedTime * 10000F * availableProcessors)); return cpuUsage; }
From source file:edu.usu.sdl.openstorefront.web.rest.service.Application.java
@GET @RequireAdmin/*from w ww . ja va2 s . co m*/ @APIDescription("Gets the application system status") @Produces({ MediaType.APPLICATION_JSON }) @DataType(ApplicationStatus.class) @Path("/status") public Response getApplicationStatus() { OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans(); MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans(); ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ApplicationStatus applicationStatus = new ApplicationStatus(); applicationStatus.setApplicationVersion(PropertiesManager.getApplicationVersion()); applicationStatus.setProcessorCount(operatingSystemMXBean.getAvailableProcessors()); applicationStatus.setSystemLoad(operatingSystemMXBean.getSystemLoadAverage()); applicationStatus.setSystemProperties(runtimeMXBean.getSystemProperties()); applicationStatus.getHeapMemoryStatus().setName("Heap"); applicationStatus.getHeapMemoryStatus().setDetails(memoryMXBean.getHeapMemoryUsage().toString()); applicationStatus.getHeapMemoryStatus() .setInitKb(memoryMXBean.getHeapMemoryUsage().getInit() != 0 ? memoryMXBean.getHeapMemoryUsage().getInit() / 1024 : 0); applicationStatus.getHeapMemoryStatus() .setUsedKb(memoryMXBean.getHeapMemoryUsage().getUsed() != 0 ? memoryMXBean.getHeapMemoryUsage().getUsed() / 1024 : 0); applicationStatus.getHeapMemoryStatus() .setMaxKb(memoryMXBean.getHeapMemoryUsage().getMax() != 0 ? memoryMXBean.getHeapMemoryUsage().getMax() / 1024 : 0); applicationStatus.getHeapMemoryStatus() .setCommitedKb(memoryMXBean.getHeapMemoryUsage().getCommitted() != 0 ? memoryMXBean.getHeapMemoryUsage().getCommitted() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus().setName("Non-Heap"); applicationStatus.getNonHeapMemoryStatus().setDetails(memoryMXBean.getNonHeapMemoryUsage().toString()); applicationStatus.getNonHeapMemoryStatus() .setInitKb(memoryMXBean.getNonHeapMemoryUsage().getInit() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getInit() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus() .setUsedKb(memoryMXBean.getNonHeapMemoryUsage().getUsed() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getUsed() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus() .setMaxKb(memoryMXBean.getNonHeapMemoryUsage().getMax() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getMax() / 1024 : 0); applicationStatus.getNonHeapMemoryStatus() .setCommitedKb(memoryMXBean.getNonHeapMemoryUsage().getCommitted() != 0 ? memoryMXBean.getNonHeapMemoryUsage().getCommitted() / 1024 : 0); applicationStatus.setLiveThreadCount(threadMXBean.getThreadCount()); applicationStatus.setTotalThreadCount(threadMXBean.getTotalStartedThreadCount()); applicationStatus.setStartTime(new Date(runtimeMXBean.getStartTime())); applicationStatus.setUpTime(TimeUtil.millisToString(runtimeMXBean.getUptime())); for (GarbageCollectorMXBean garbageCollectorMXBean : garbageCollectorMXBeans) { applicationStatus.getGarbageCollectionInfos() .add(TimeUtil.millisToString(garbageCollectorMXBean.getCollectionTime()) + " - (" + garbageCollectorMXBean.getCollectionCount() + ")"); } for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) { MemoryPoolStatus memoryPoolStatus = new MemoryPoolStatus(); memoryPoolStatus.setName(memoryPoolMXBean.getName() + " - " + memoryPoolMXBean.getType()); memoryPoolStatus.setDetails(memoryPoolMXBean.getUsage().toString()); memoryPoolStatus.setInitKb( memoryPoolMXBean.getUsage().getInit() != 0 ? memoryPoolMXBean.getUsage().getInit() / 1024 : 0); memoryPoolStatus.setUsedKb( memoryPoolMXBean.getUsage().getUsed() != 0 ? memoryPoolMXBean.getUsage().getUsed() / 1024 : 0); memoryPoolStatus.setMaxKb( memoryPoolMXBean.getUsage().getMax() != 0 ? memoryPoolMXBean.getUsage().getMax() / 1024 : 0); memoryPoolStatus.setCommitedKb(memoryPoolMXBean.getUsage().getCommitted() != 0 ? memoryPoolMXBean.getUsage().getCommitted() / 1024 : 0); applicationStatus.getMemoryPools().add(memoryPoolStatus); } return sendSingleEntityResponse(applicationStatus); }