Search in sources :

Example 86 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project n2a by frothga.

the class Host method getProcessorIdle.

/**
 *        @return Number of processors available to use. This is directly comparable to the result of getProcessorTotal().
 *        If the system has 32 processors and they are all 75% idle, then the return value is 24.0.
 */
public double getProcessorIdle() {
    int nproc = getProcessorTotal();
    OperatingSystemMXBean OS = ManagementFactory.getOperatingSystemMXBean();
    try {
        return nproc - (Double) invoke(OS, "getSystemCpuLoad");
    } catch (Exception e) {
        // TODO: known to fail on Windows
        return nproc - Math.max(0, OS.getSystemLoadAverage());
    }
}
Also used : ExtensionPoint(gov.sandia.n2a.plugins.ExtensionPoint) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException) AccessDeniedException(java.nio.file.AccessDeniedException)

Example 87 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project support-core-plugin by jenkinsci.

the class FileDescriptorLimit method getOpenFileDescriptorCount.

/**
 * * Using OperatingSystemMXBean, we can obtain the total number of open file descriptors.
 */
// UnixOperatingSystemMXBean
@IgnoreJRERequirement
private static void getOpenFileDescriptorCount(PrintWriter writer) {
    try {
        OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
        if (operatingSystemMXBean instanceof UnixOperatingSystemMXBean) {
            UnixOperatingSystemMXBean unixOperatingSystemMXBean = (UnixOperatingSystemMXBean) operatingSystemMXBean;
            writer.println("Open File Descriptor Count: " + unixOperatingSystemMXBean.getOpenFileDescriptorCount());
        } else {
            writer.println("Wrong bean: " + operatingSystemMXBean);
        }
    } catch (LinkageError e) {
        writer.println("Unable to get the total number of open file descriptors using OperatingSystemMXBean");
    }
}
Also used : UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) IgnoreJRERequirement(org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement)

Example 88 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class StoreUtil method getTotalPhysicalMemorySize.

@SuppressWarnings("restriction")
public static long getTotalPhysicalMemorySize() {
    long physicalTotal = 1024 * 1024 * 1024 * 24L;
    OperatingSystemMXBean osmxb = ManagementFactory.getOperatingSystemMXBean();
    if (osmxb instanceof com.sun.management.OperatingSystemMXBean) {
        physicalTotal = ((com.sun.management.OperatingSystemMXBean) osmxb).getTotalPhysicalMemorySize();
    }
    return physicalTotal;
}
Also used : OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Example 89 with OperatingSystemMXBean

use of java.lang.management.OperatingSystemMXBean in project uavstack by uavorg.

the class JVMStateCapHandler method readCPUUsage.

protected void readCPUUsage(MonitorElementInstance inst) {
    OperatingSystemMXBean osMBean = ManagementFactory.getOperatingSystemMXBean();
    Double procCPU = (Double) ReflectionHelper.invoke("com.sun.management.OperatingSystemMXBean", osMBean, "getProcessCpuLoad", null, null);
    Double systemCPU = (Double) ReflectionHelper.invoke("com.sun.management.OperatingSystemMXBean", osMBean, "getSystemCpuLoad", null, null);
    if (procCPU == null) {
        procCPU = JVMToolHelper.getProcessCpuUtilization();
        systemCPU = -1D;
    }
    inst.setValue("cpu_p", Double.valueOf(formatter.format(procCPU * 100)));
    inst.setValue("cpu_s", Double.valueOf(formatter.format(systemCPU * 100)));
}
Also used : OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean)

Aggregations

OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)89 RuntimeMXBean (java.lang.management.RuntimeMXBean)27 Method (java.lang.reflect.Method)20 IOException (java.io.IOException)15 MemoryMXBean (java.lang.management.MemoryMXBean)12 MemoryUsage (java.lang.management.MemoryUsage)8 ThreadMXBean (java.lang.management.ThreadMXBean)8 HashMap (java.util.HashMap)8 UnixOperatingSystemMXBean (com.sun.management.UnixOperatingSystemMXBean)7 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)6 Status (com.alibaba.dubbo.common.status.Status)5 File (java.io.File)5 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 Test (org.junit.Test)5 Test (org.testng.annotations.Test)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 UnknownHostException (java.net.UnknownHostException)4 Date (java.util.Date)4 ExtendedOperatingSystemMXBeanImpl (com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl)3