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