Java Code Examples for java.lang.management.RuntimeMXBean#getUptime()
The following examples show how to use
java.lang.management.RuntimeMXBean#getUptime() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PitError.java From pitest with Apache License 2.0 | 6 votes |
private static String info() { final RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean(); return "\n\nPlease copy and paste the information and the complete stacktrace below when reporting an issue\n" + "VM : " + rt.getVmName() + "\n" + "Vendor : " + rt.getVmVendor() + "\n" + "Version : " + rt.getVmVersion() + "\n" + "Uptime : " + rt.getUptime() + "\n" + "Input -> " + createInputString(rt.getInputArguments()) + "\n" + "BootClassPathSupported : " + rt.isBootClassPathSupported() + "\n"; }
Example 2
Source File: AppInfo.java From vi with Apache License 2.0 | 6 votes |
@Override public void refresh() { if(HostInfo.isTomcat()){ webInfo = "view"; } RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); upTime = runtimeBean.getUptime(); EnApp enApp = EnFactory.getEnApp(); enApp.refresh(); appid = nullToNA(EnFactory.getEnBase().getAppId()); appName = nullToNA(enApp.getName()); appChineseName = nullToNA(enApp.getChineseName()); appOwner = nullToNA(enApp.getOwner()); appOwnerEmail = nullToNA(enApp.getOwnerContact()); appBackup = nullToNA(enApp.getBackup()); appVersion = nullToNA(enApp.getVersion()); buildTime = nullToNA(enApp.getBuildTime()); getStatus(); }
Example 3
Source File: GetStatusServlet.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private static void getSystemInfo( SlaveServerStatus serverStatus ) { OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); int cores = Runtime.getRuntime().availableProcessors(); long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); String osArch = operatingSystemMXBean.getArch(); String osName = operatingSystemMXBean.getName(); String osVersion = operatingSystemMXBean.getVersion(); double loadAvg = operatingSystemMXBean.getSystemLoadAverage(); int threadCount = threadMXBean.getThreadCount(); long allThreadsCpuTime = 0L; long[] threadIds = threadMXBean.getAllThreadIds(); for ( int i = 0; i < threadIds.length; i++ ) { allThreadsCpuTime += threadMXBean.getThreadCpuTime( threadIds[ i ] ); } long uptime = runtimeMXBean.getUptime(); serverStatus.setCpuCores( cores ); serverStatus.setCpuProcessTime( allThreadsCpuTime ); serverStatus.setUptime( uptime ); serverStatus.setThreadCount( threadCount ); serverStatus.setLoadAvg( loadAvg ); serverStatus.setOsName( osName ); serverStatus.setOsVersion( osVersion ); serverStatus.setOsArchitecture( osArch ); serverStatus.setMemoryFree( freeMemory ); serverStatus.setMemoryTotal( totalMemory ); }
Example 4
Source File: JVMToolHelper.java From uavstack with Apache License 2.0 | 6 votes |
/** * obtain current process cpu utilization if jdk version is 1.6 by-hongqiangwei */ @SuppressWarnings("restriction") public static double getProcessCpuUtilization() { com.sun.management.OperatingSystemMXBean osMBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory .getOperatingSystemMXBean(); RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); long processCpuTime1 = osMBean.getProcessCpuTime(); long runtime1 = runtimeMXBean.getUptime(); ThreadHelper.suspend(50); long processCpuTime2 = osMBean.getProcessCpuTime(); long runtime2 = runtimeMXBean.getUptime(); long deltaProcessTime = processCpuTime2 - processCpuTime1; long deltaRunTime = (runtime2 - runtime1) * 1000000L; int cpuNumber = Runtime.getRuntime().availableProcessors(); double cpuUtilization = (double) deltaProcessTime / (deltaRunTime * cpuNumber); return cpuUtilization; }
Example 5
Source File: UptimeCommand.java From vk-java-sdk with MIT License | 6 votes |
@Override public void run() throws ClientException, ApiException { RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean(); long uptime = mxBean.getUptime(); String hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(uptime), TimeUnit.MILLISECONDS.toMinutes(uptime) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(uptime)), TimeUnit.MILLISECONDS.toSeconds(uptime) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(uptime))); String msg = "Uptime is " + hms + ".\n" + "Statistics: \n" + "Executed commands " + Statistic.get(Statistic.Event.COMMAND) + "\n" + "Failed commands " + Statistic.get(Statistic.Event.FAILED_COMMAND) + "\n" + "Loaded users " + YouTrackUsersStorage.getInstance().getCount(); sendMessage(msg); }
Example 6
Source File: LocatorStatusResponse.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
public LocatorStatusResponse initialize(final int locatorPort, final String locatorHost, final String locatorLogFile, final String locatorName) { final RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); this.pid = identifyPid(); this.jvmArgs = runtimeBean.getInputArguments(); this.uptime = runtimeBean.getUptime(); this.classpath = runtimeBean.getClassPath(); this.gemfireVersion = GemFireVersion.getGemFireVersion(); this.javaVersion = System.getProperty("java.version"); this.workingDirectory = System.getProperty("user.dir"); this.logFile = locatorLogFile; this.host = locatorHost; this.port = locatorPort; this.name = locatorName; return this; }
Example 7
Source File: RuntimeInformationProvider.java From gocd with Apache License 2.0 | 6 votes |
@Override public Map<String, Object> asJson() { RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); long uptime = runtimeMXBean.getUptime(); long uptimeInSeconds = uptime / 1000; long numberOfHours = uptimeInSeconds / (60 * 60); long numberOfMinutes = (uptimeInSeconds / 60) - (numberOfHours * 60); long numberOfSeconds = uptimeInSeconds % 60; LinkedHashMap<String, Object> json = new LinkedHashMap<>(); json.put("Name", runtimeMXBean.getName()); json.put("Uptime", runtimeMXBean.getUptime()); json.put("Uptime (in Time Format)", "[About " + numberOfHours + " hours, " + numberOfMinutes + " minutes, " + numberOfSeconds + " seconds]"); json.put("Spec Name", runtimeMXBean.getSpecName()); json.put("Spec Vendor", runtimeMXBean.getSpecVendor()); json.put("Spec Version", runtimeMXBean.getSpecVersion()); json.put("Input Arguments", runtimeMXBean.getInputArguments()); json.put("System Properties", new TreeMap<>(asIndentedMultilineValuesAsJson(runtimeMXBean.getSystemProperties()))); json.put("Environment Variables", new TreeMap<>(asIndentedMultilineValuesAsJson(System.getenv()))); return json; }
Example 8
Source File: ServerStatus.java From hop with Apache License 2.0 | 5 votes |
public ServerStatus() { OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); int cores = Runtime.getRuntime().availableProcessors(); long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); String osArch = operatingSystemMXBean.getArch(); String osName = operatingSystemMXBean.getName(); String osVersion = operatingSystemMXBean.getVersion(); double loadAvg = operatingSystemMXBean.getSystemLoadAverage(); int threadCount = threadMXBean.getThreadCount(); long allThreadsCpuTime = 0L; long[] threadIds = threadMXBean.getAllThreadIds(); for ( int i = 0; i < threadIds.length; i++ ) { allThreadsCpuTime += threadMXBean.getThreadCpuTime( threadIds[ i ] ); } long uptime = runtimeMXBean.getUptime(); setCpuCores( cores ); setCpuProcessTime( allThreadsCpuTime ); setUptime( uptime ); setThreadCount( threadCount ); setLoadAvg( loadAvg ); setOsName( osName ); setOsVersion( osVersion ); setOsArchitecture( osArch ); setMemoryFree( freeMemory ); setMemoryTotal( totalMemory ); }
Example 9
Source File: SystemCommand.java From LagMonitor with MIT License | 5 votes |
private void displayRuntimeInfo(CommandSender sender, RuntimeMXBean runtimeBean) { long uptime = runtimeBean.getUptime(); String uptimeFormat = LagMonitor.formatDuration(Duration.ofMillis(uptime)); displayMemoryInfo(sender, Runtime.getRuntime()); // runtime specific sendMessage(sender, "Uptime", uptimeFormat); sendMessage(sender, "Arguments", runtimeBean.getInputArguments().toString()); sendMessage(sender, "Classpath", runtimeBean.getClassPath()); sendMessage(sender, "Library path", runtimeBean.getLibraryPath()); }
Example 10
Source File: SimplePerfTest.java From logging-log4j2 with Apache License 2.0 | 5 votes |
private static void runTest(final Logger logger, final RuntimeMXBean runtimeMXBean, final long[] UPTIMES, final long[] DURATIONS, final int index) { UPTIMES[index] = runtimeMXBean.getUptime(); final long startNanos = System.nanoTime(); loop(logger, ITERATIONS); final long endNanos = System.nanoTime(); DURATIONS[index] = endNanos - startNanos; }
Example 11
Source File: SystemCommand.java From LagMonitor with MIT License | 5 votes |
private void displayRuntimeInfo(CommandSender sender, RuntimeMXBean runtimeBean) { long uptime = runtimeBean.getUptime(); String uptimeFormat = LagMonitor.formatDuration(Duration.ofMillis(uptime)); displayMemoryInfo(sender, Runtime.getRuntime()); // runtime specific sendMessage(sender, "Uptime", uptimeFormat); sendMessage(sender, "Arguments", runtimeBean.getInputArguments().toString()); sendMessage(sender, "Classpath", runtimeBean.getClassPath()); sendMessage(sender, "Library path", runtimeBean.getLibraryPath()); }
Example 12
Source File: MonitoredDataImpl.java From visualvm with GNU General Public License v2.0 | 5 votes |
MonitoredDataImpl(JmxSupport jmxSupport,JvmMXBeans jmxModel) { this(jmxSupport); RuntimeMXBean runtimeBean = jmxModel.getRuntimeMXBean(); upTime = runtimeBean.getUptime(); ClassLoadingMXBean classBean = jmxModel.getClassLoadingMXBean(); ThreadMXBean threadBean = jmxModel.getThreadMXBean(); MemoryUsage mem = jmxModel.getMemoryMXBean().getHeapMemoryUsage(); MemoryPoolMXBean permBean = jmxSupport.getPermGenPool(); unloadedClasses = classBean.getUnloadedClassCount(); loadedClasses = classBean.getLoadedClassCount() + unloadedClasses; sharedLoadedClasses = 0; sharedUnloadedClasses = 0; threadsDaemon = threadBean.getDaemonThreadCount(); threadsLive = threadBean.getThreadCount(); threadsLivePeak = threadBean.getPeakThreadCount(); threadsStarted = threadBean.getTotalStartedThreadCount(); applicationTime = 0; genCapacity = new long[2]; genUsed = new long[2]; genMaxCapacity = new long[2]; genCapacity[0] = mem.getCommitted(); genUsed[0] = mem.getUsed(); genMaxCapacity[0] = mem.getMax(); if (permBean != null) { MemoryUsage perm = permBean.getUsage(); genCapacity[1] = perm.getCommitted(); genUsed[1] = perm.getUsed(); genMaxCapacity[1] = perm.getMax(); } }
Example 13
Source File: SystemStatusListener.java From Sentinel with Apache License 2.0 | 5 votes |
@Override public void run() { try { OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class); currentLoad = osBean.getSystemLoadAverage(); /* * Java Doc copied from {@link OperatingSystemMXBean#getSystemCpuLoad()}:</br> * Returns the "recent cpu usage" for the whole system. This value is a double in the [0.0,1.0] interval. * A value of 0.0 means that all CPUs were idle during the recent period of time observed, while a value * of 1.0 means that all CPUs were actively running 100% of the time during the recent period being * observed. All values between 0.0 and 1.0 are possible depending of the activities going on in the * system. If the system recent cpu usage is not available, the method returns a negative value. */ double systemCpuUsage = osBean.getSystemCpuLoad(); // calculate process cpu usage to support application running in container environment RuntimeMXBean runtimeBean = ManagementFactory.getPlatformMXBean(RuntimeMXBean.class); long newProcessCpuTime = osBean.getProcessCpuTime(); long newProcessUpTime = runtimeBean.getUptime(); int cpuCores = osBean.getAvailableProcessors(); long processCpuTimeDiffInMs = TimeUnit.NANOSECONDS .toMillis(newProcessCpuTime - processCpuTime); long processUpTimeDiffInMs = newProcessUpTime - processUpTime; double processCpuUsage = (double) processCpuTimeDiffInMs / processUpTimeDiffInMs / cpuCores; processCpuTime = newProcessCpuTime; processUpTime = newProcessUpTime; currentCpuUsage = Math.max(processCpuUsage, systemCpuUsage); if (currentLoad > SystemRuleManager.getSystemLoadThreshold()) { writeSystemStatusLog(); } } catch (Throwable e) { RecordLog.warn("[SystemStatusListener] Failed to get system metrics from JMX", e); } }
Example 14
Source File: GetStatusServlet.java From hop with Apache License 2.0 | 5 votes |
private static void getSystemInfo( HopServerStatus serverStatus ) { OperatingSystemMXBean operatingSystemMXBean = java.lang.management.ManagementFactory.getOperatingSystemMXBean(); ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean(); RuntimeMXBean runtimeMXBean = java.lang.management.ManagementFactory.getRuntimeMXBean(); int cores = Runtime.getRuntime().availableProcessors(); long freeMemory = Runtime.getRuntime().freeMemory(); long totalMemory = Runtime.getRuntime().totalMemory(); String osArch = operatingSystemMXBean.getArch(); String osName = operatingSystemMXBean.getName(); String osVersion = operatingSystemMXBean.getVersion(); double loadAvg = operatingSystemMXBean.getSystemLoadAverage(); int threadCount = threadMXBean.getThreadCount(); long allThreadsCpuTime = 0L; long[] threadIds = threadMXBean.getAllThreadIds(); for ( int i = 0; i < threadIds.length; i++ ) { allThreadsCpuTime += threadMXBean.getThreadCpuTime( threadIds[ i ] ); } long uptime = runtimeMXBean.getUptime(); serverStatus.setCpuCores( cores ); serverStatus.setCpuProcessTime( allThreadsCpuTime ); serverStatus.setUptime( uptime ); serverStatus.setThreadCount( threadCount ); serverStatus.setLoadAvg( loadAvg ); serverStatus.setOsName( osName ); serverStatus.setOsVersion( osVersion ); serverStatus.setOsArchitecture( osArch ); serverStatus.setMemoryFree( freeMemory ); serverStatus.setMemoryTotal( totalMemory ); }
Example 15
Source File: Controller.java From floodlight_with_topoguard with Apache License 2.0 | 4 votes |
@Override public Long getUptime() { RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); return rb.getUptime(); }
Example 16
Source File: MockFloodlightProvider.java From floodlight_with_topoguard with Apache License 2.0 | 4 votes |
@Override public Long getUptime() { RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); return rb.getUptime(); }
Example 17
Source File: SingularityLeaderController.java From Singularity with Apache License 2.0 | 4 votes |
private SingularityHostState getHostState() { final boolean master = isMaster(); final RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean(); final long uptime = mxBean.getUptime(); final long now = System.currentTimeMillis(); final Optional<Long> lastOfferTimestamp = getLastOfferTimestamp(); final Optional<Long> millisSinceLastOfferTimestamp = lastOfferTimestamp.isPresent() ? Optional.of(now - lastOfferTimestamp.get()) : Optional.<Long>empty(); String mesosMaster = null; Optional<MasterInfo> mesosMasterInfo = getMaster(); if (mesosMasterInfo.isPresent()) { mesosMaster = MesosUtils.getMasterHostAndPort(mesosMasterInfo.get()); } double cachedCpus = 0; double cachedMemoryBytes = 0; int numCachedOffers = 0; for (Offer offer : offerCache.peekOffers()) { cachedCpus += MesosUtils.getNumCpus(offer); cachedMemoryBytes += MesosUtils.getMemory(offer); numCachedOffers++; } return new SingularityHostState( master, uptime, scheduler.getState().getMesosSchedulerState().name(), millisSinceLastOfferTimestamp, hostAndPort.getHost(), hostAndPort.getHost(), mesosMaster, scheduler.isRunning(), numCachedOffers, cachedCpus, cachedMemoryBytes ); }
Example 18
Source File: Controller.java From onos with Apache License 2.0 | 4 votes |
public Long getUptime() { RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); return rb.getUptime(); }
Example 19
Source File: AppInfo.java From vi with Apache License 2.0 | 3 votes |
public AppInfo() { RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean(); AppStartUpTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(runtimeBean.getStartTime())); upTime = runtimeBean.getUptime(); }
Example 20
Source File: Controller.java From onos with Apache License 2.0 | 2 votes |
/** * Gets UP time. * * @return UP time */ public Long getUptime() { RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); return rb.getUptime(); }