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.");
}
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());
}
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);
}
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);
}
}
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;
}
}
Aggregations