List of usage examples for java.lang.management OperatingSystemMXBean getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:api.Status.java
public static Result getStatus() { ObjectNode metrics = Json.newObject(); OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); TreeMap<String, Object> values = new TreeMap<String, Object>(); for (Method method : os.getClass().getDeclaredMethods()) { method.setAccessible(true);/* ww w .j av a2 s . co m*/ if (method.getName().startsWith("get") && Modifier.isPublic(method.getModifiers())) { Object value; try { value = method.invoke(os); values.put(method.getName(), value); } catch (Exception e) { Logger.warn("Error when invoking " + os.getClass().getName() + " (OperatingSystemMXBean) method " + method.getName() + ": " + e); } // try } // if } // for metrics.put("jvmLoad", (Double) values.get("getProcessCpuLoad")); metrics.put("cpuLoad", (Double) values.get("getSystemCpuLoad")); metrics.put("openFD", (Long) values.get("getOpenFileDescriptorCount")); metrics.put("maxFD", (Long) values.get("getMaxFileDescriptorCount")); metrics.put("freeMemory", (Long) values.get("getFreePhysicalMemorySize")); metrics.put("totalMemory", (Long) values.get("getTotalPhysicalMemorySize")); return ok(metrics.toString()); }
From source file:net.bull.javamelody.internal.model.JavaInformations.java
private static boolean isSunUnixMBean(OperatingSystemMXBean operatingSystem) { for (final Class<?> inter : operatingSystem.getClass().getInterfaces()) { if ("com.sun.management.UnixOperatingSystemMXBean".equals(inter.getName())) { return true; }// ww w . j a v a 2 s . com } return false; }
From source file:net.ftb.util.OSUtils.java
private static long getOSMemory(String methodName, String warning) { long ram = 0; OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); Method m;//www . j ava 2s . co m try { m = operatingSystemMXBean.getClass().getDeclaredMethod(methodName); m.setAccessible(true); Object value = m.invoke(operatingSystemMXBean); if (value != null) { ram = Long.valueOf(value.toString()) / 1024 / 1024; } else { Logger.logWarn(warning); ram = 1024; } } catch (Exception e) { Logger.logError("Error while getting OS memory info", e); } return ram; }
From source file:net.centro.rtb.monitoringcenter.infos.OperatingSystemInfo.java
public static OperatingSystemInfo create() { OperatingSystemInfo operatingSystemInfo = new OperatingSystemInfo(); OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean(); operatingSystemInfo.name = operatingSystemMXBean.getName(); operatingSystemInfo.version = operatingSystemMXBean.getVersion(); if (SystemUtils.IS_OS_LINUX) { operatingSystemInfo.distributionName = resolveLinuxDistributionName(); }//ww w . jav a 2 s . c o m operatingSystemInfo.architecture = operatingSystemMXBean.getArch(); operatingSystemInfo.numberOfLogicalProcessors = operatingSystemMXBean.getAvailableProcessors(); if (com.sun.management.OperatingSystemMXBean.class.isAssignableFrom(operatingSystemMXBean.getClass())) { com.sun.management.OperatingSystemMXBean sunOsMxBean = com.sun.management.OperatingSystemMXBean.class .cast(operatingSystemMXBean); operatingSystemInfo.physicalMemorySizeInBytes = sunOsMxBean.getTotalPhysicalMemorySize(); operatingSystemInfo.swapSpaceSizeInBytes = sunOsMxBean.getTotalSwapSpaceSize(); } Map<String, Long> diskSpaceInBytesByRootPaths = new HashMap<>(); for (File rootFile : File.listRoots()) { diskSpaceInBytesByRootPaths.put(rootFile.getAbsolutePath(), rootFile.getTotalSpace()); } operatingSystemInfo.diskSpaceInBytesByRootPaths = diskSpaceInBytesByRootPaths; return operatingSystemInfo; }
From source file:net.bull.javamelody.internal.model.JavaInformations.java
private static boolean isSunOsMBean(OperatingSystemMXBean operatingSystem) { // on ne teste pas operatingSystem instanceof com.sun.management.OperatingSystemMXBean // car le package com.sun n'existe priori pas sur une jvm tierce final String className = operatingSystem.getClass().getName(); return "com.sun.management.OperatingSystem".equals(className) || "com.sun.management.UnixOperatingSystem".equals(className) // sun.management.OperatingSystemImpl pour java 8 || "sun.management.OperatingSystemImpl".equals(className); }
From source file:org.jenkinsci.remoting.engine.HandlerLoopbackLoadStress.java
private static Method _getProcessCpuTime(OperatingSystemMXBean operatingSystemMXBean) { Method getProcessCpuTime;/*ww w .j a v a2 s. co m*/ try { getProcessCpuTime = operatingSystemMXBean.getClass().getMethod("getProcessCpuTime"); getProcessCpuTime.setAccessible(true); } catch (ClassCastException e) { getProcessCpuTime = null; } catch (NoSuchMethodException e) { getProcessCpuTime = null; } return getProcessCpuTime; }