Search in sources :

Example 6 with OperatingSystemMXBean

use of com.sun.management.OperatingSystemMXBean in project jdk8u_jdk by JetBrains.

the class MemoryStatusOverflow method main.

public static void main(String... args) throws Exception {
    OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    List<String> failedGetterNames = new ArrayList<String>();
    List<String> testedGetterNames = Arrays.asList("getTotalSwapSpaceSize", "getFreeSwapSpaceSize", "getTotalPhysicalMemorySize", "getFreePhysicalMemorySize");
    for (String getterName : testedGetterNames) {
        Method getter = OperatingSystemMXBean.class.getMethod(getterName);
        long value = (Long) getter.invoke(bean);
        if (value == MEMORYSTATUS_OVERFLOW) {
            failedGetterNames.add(getterName);
        }
    }
    if (!failedGetterNames.isEmpty()) {
        throw new AssertionError(failedGetterNames);
    }
    System.out.println("Test passed.");
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) OperatingSystemMXBean(com.sun.management.OperatingSystemMXBean)

Example 7 with OperatingSystemMXBean

use of com.sun.management.OperatingSystemMXBean in project Gargoyle by callakrsos.

the class CPUUsageTest method showOSBean.

/**
	 * OS 정보
	 */
public void showOSBean() {
    OperatingSystemMXBean osbean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    System.out.println("OS Name: " + osbean.getName());
    System.out.println("OS Arch: " + osbean.getArch());
    System.out.println("Available Processors: " + osbean.getAvailableProcessors());
    System.out.println("TotalPhysicalMemorySize: " + osbean.getTotalPhysicalMemorySize());
    System.out.println("FreePhysicalMemorySize: " + osbean.getFreePhysicalMemorySize());
    System.out.println("TotalSwapSpaceSize: " + osbean.getTotalSwapSpaceSize());
    System.out.println("FreeSwapSpaceSize: " + osbean.getFreeSwapSpaceSize());
    System.out.println("CommittedVirtualMemorySize: " + osbean.getCommittedVirtualMemorySize());
    System.out.println("SystemLoadAverage: " + osbean.getSystemLoadAverage());
}
Also used : OperatingSystemMXBean(com.sun.management.OperatingSystemMXBean)

Example 8 with OperatingSystemMXBean

use of com.sun.management.OperatingSystemMXBean in project Gargoyle by callakrsos.

the class CPUUsageTest method showCPU.

/*
	 * cpu 사용량
	 */
public static void showCPU() {
    OperatingSystemMXBean osbean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    RuntimeMXBean runbean = ManagementFactory.getRuntimeMXBean();
    long bfprocesstime = osbean.getProcessCpuTime();
    long bfuptime = runbean.getUptime();
    long ncpus = osbean.getAvailableProcessors();
    //		for (int i = 0; i < 1000000; ++i) {
    //			ncpus = osbean.getAvailableProcessors();
    //		}
    long afprocesstime = osbean.getProcessCpuTime();
    long afuptime = runbean.getUptime();
    float cal = (afprocesstime - bfprocesstime) / ((afuptime - bfuptime) * 10000f);
    float usage = Math.min(99f, cal);
    System.out.println("Calculation: " + cal);
    System.out.println("CPU Usage: " + usage);
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean) OperatingSystemMXBean(com.sun.management.OperatingSystemMXBean)

Example 9 with OperatingSystemMXBean

use of com.sun.management.OperatingSystemMXBean in project flink by apache.

the class TaskExecutorMetricsInitializer method instantiateCPUMetrics.

private static void instantiateCPUMetrics(MetricGroup metrics) {
    try {
        final OperatingSystemMXBean mxBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        metrics.<Double, Gauge<Double>>gauge("Load", new Gauge<Double>() {

            @Override
            public Double getValue() {
                return mxBean.getProcessCpuLoad();
            }
        });
        metrics.<Long, Gauge<Long>>gauge("Time", new Gauge<Long>() {

            @Override
            public Long getValue() {
                return mxBean.getProcessCpuTime();
            }
        });
    } catch (Exception e) {
        LOG.warn("Cannot access com.sun.management.OperatingSystemMXBean.getProcessCpuLoad()" + " - CPU load metrics will not be available.", e);
    }
}
Also used : OperatingSystemMXBean(com.sun.management.OperatingSystemMXBean) AttributeNotFoundException(javax.management.AttributeNotFoundException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) Gauge(org.apache.flink.metrics.Gauge)

Example 10 with OperatingSystemMXBean

use of com.sun.management.OperatingSystemMXBean in project processdash by dtuma.

the class RuntimeUtils method getSuggestedMaxJvmHeapSize.

/**
     * JVMs are often started with a -Xmx argument to set the max heap size.
     * This method will return the suggested maximum amount of memory that
     * should be used for such an argument, based on the current operating
     * system and JVM environment.
     * 
     * @since 1.15.0.4
     */
public static long getSuggestedMaxJvmHeapSize() {
    try {
        Object bean = ManagementFactory.getOperatingSystemMXBean();
        OperatingSystemMXBean osMxBean = (OperatingSystemMXBean) bean;
        long systemMemoryBytes = osMxBean.getTotalPhysicalMemorySize();
        long systemMemoryMegabytes = systemMemoryBytes >> 20;
        long halfOfMemory = systemMemoryMegabytes / 2;
        long result = halfOfMemory;
        // running, and choose a more conservative limit as appropriate.
        if ("64".equals(System.getProperty("sun.arch.data.model")))
            result = Math.min(halfOfMemory, 2000);
        else
            result = Math.min(halfOfMemory, 1000);
        return result;
    } catch (Throwable t) {
        // In that case, use a conservative threshhold.
        return 800;
    }
}
Also used : 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