Search in sources :

Example 11 with OperatingSystemMXBean

use of com.sun.management.OperatingSystemMXBean in project scheduling by ow2-proactive.

the class RamCompute method getAvailableRAMInGB.

/**
 * @return the total GIGA of RAM available in a machine minus the RAM preallocated by a task.
 */
public double getAvailableRAMInGB() {
    OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    double totRAMAvailable = ((double) bean.getTotalPhysicalMemorySize()) / GIGABYTE;
    double totalRAMUsed = 0;
    for (LocalNode localNode : ProActiveRuntimeImpl.getProActiveRuntime().getLocalNodes()) {
        if (localNode.getProperty(RamSchedulingPolicy.RAM_VARIABLE_NAME) != null) {
            totalRAMUsed += Double.parseDouble(localNode.getProperty(RamSchedulingPolicy.RAM_VARIABLE_NAME));
        }
    }
    double ramInBytes = totRAMAvailable - totalRAMUsed;
    return ramInBytes;
}
Also used : LocalNode(org.objectweb.proactive.core.runtime.LocalNode) OperatingSystemMXBean(com.sun.management.OperatingSystemMXBean)

Aggregations

OperatingSystemMXBean (com.sun.management.OperatingSystemMXBean)11 RuntimeMXBean (java.lang.management.RuntimeMXBean)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 AttributeNotFoundException (javax.management.AttributeNotFoundException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanException (javax.management.MBeanException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ReflectionException (javax.management.ReflectionException)1 Gauge (org.apache.flink.metrics.Gauge)1 LocalNode (org.objectweb.proactive.core.runtime.LocalNode)1