本文整理匯總了Java中java.lang.management.OperatingSystemMXBean.getSystemLoadAverage方法的典型用法代碼示例。如果您正苦於以下問題:Java OperatingSystemMXBean.getSystemLoadAverage方法的具體用法?Java OperatingSystemMXBean.getSystemLoadAverage怎麽用?Java OperatingSystemMXBean.getSystemLoadAverage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.lang.management.OperatingSystemMXBean
的用法示例。
在下文中一共展示了OperatingSystemMXBean.getSystemLoadAverage方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getOsInfo
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
public static void getOsInfo() {
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
//os general info
String osName = osBean.getName();
String osVersion = osBean.getVersion();
String osArch = osBean.getArch();
//CPU
int cores = osBean.getAvailableProcessors();
String cpuName = System.getenv("PROCESSOR_IDENTIFIER");
//only on *nix systems
double loadAvg = osBean.getSystemLoadAverage();
if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
getExtendedOsInfo((com.sun.management.OperatingSystemMXBean) osBean);
}
}
示例2: call
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
@Override
public String call() {
Map<String, String> memoryMap = new HashMap<>();
OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
double cpu = osMxBean.getSystemLoadAverage();
memoryMap.put("cpuLoad", String.format(doubleStringFormatter, round(cpu, doubleRoundPlaces)));
ThreadMXBean threadmxBean = ManagementFactory.getThreadMXBean();
int threadCount = threadmxBean.getThreadCount();
memoryMap.put("cpuRunningThreads", String.valueOf(threadCount));
MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
MemoryUsage memHeapUsage = memBean.getHeapMemoryUsage();
MemoryUsage nonHeapUsage = memBean.getNonHeapMemoryUsage();
memoryMap.put("heapInit", String.valueOf(memHeapUsage.getInit()));
memoryMap.put("heapMax", String.valueOf(memHeapUsage.getMax()));
memoryMap.put("heapCommit", String.valueOf(memHeapUsage.getCommitted()));
memoryMap.put("heapUsed", String.valueOf(memHeapUsage.getUsed()));
memoryMap.put("nonHeapInit", String.valueOf(nonHeapUsage.getInit()));
memoryMap.put("nonHeapMax", String.valueOf(nonHeapUsage.getMax()));
memoryMap.put("nonHeapCommit", String.valueOf(nonHeapUsage.getCommitted()));
memoryMap.put("nonHeapUsed", String.valueOf(nonHeapUsage.getUsed()));
return memoryMap.toString();
}
示例3: bindTo
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
@Override
public void bindTo(MeterRegistry registry) {
Runtime runtime = Runtime.getRuntime();
Gauge.builder("system.cpu.count", runtime, Runtime::availableProcessors)
.tags(tags)
.description("The number of processors available to the Java virtual machine")
.register(registry);
OperatingSystemMXBean operatingSystemBean = ManagementFactory.getOperatingSystemMXBean();
if(operatingSystemBean != null && operatingSystemBean.getSystemLoadAverage() >= 0) {
Gauge.builder("system.load.average.1m", operatingSystemBean, OperatingSystemMXBean::getSystemLoadAverage)
.tags(tags)
.description("The sum of the number of runnable entities queued to available processors and the number " +
"of runnable entities running on the available processors averaged over a period of time")
.register(registry);
}
}
示例4: systemCpuLoadAvailable
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
private static synchronized int systemCpuLoadAvailable() {
if (systemCpuLoadAvailable == -1) {
Object systemLoad = retrieveLoadAttribute(SYSTEMATTRIBUTE);
if (systemLoad == null) {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
double averageLoad = operatingSystemMXBean.getSystemLoadAverage();
if (averageLoad >= 0) {
log.info(
"System CPU load is measured with the Java method getSystemLoadAverage() of the OperatingSystemMXBean.");
systemCpuLoadAvailable = 1;
} else {
log.warn("Unable to measure System CPU load on this operating system and Java VM");
systemCpuLoadAvailable = 0;
}
} else {
log.warn("System CPU load is measured with attribute " + SYSTEMATTRIBUTE + " of OperatingSystemMXBean. "
+ "This may be an expensive method dependend on the operating system and Java VM");
systemCpuLoadAvailable = 2;
}
}
return systemCpuLoadAvailable;
}
示例5: Average
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
@JMXBeanAttribute(name = "CPU: System Load Average (%)", description = "the recent cpu usage for the whole system. -1 if not available", sortValue = "f1")
public double getSystemCpuLoad() {
switch (systemCpuLoadAvailable) {
case 0:
return -1;
case 1:
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
double load = operatingSystemMXBean.getSystemLoadAverage() * 100
/ operatingSystemMXBean.getAvailableProcessors();
return load;
case 2:
return (double) retrieveLoadAttribute(SYSTEMATTRIBUTE) * 100;
default:
return -1;
}
}
示例6: getOSInfo
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
/***
* Get OS information.
*/
private static void getOSInfo(){
OperatingSystemMXBean osbean = ManagementFactory.getOperatingSystemMXBean();
osName = osbean.getName();
osArch = osbean.getArch();
osVersion = osbean.getVersion();
cpuUsage = osbean.getSystemLoadAverage();
availableProcessors = osbean.getAvailableProcessors();
}
示例7: logCpuStats
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
/**
* Log the CPU stats
*/
public static void logCpuStats() {
OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
int availableProcessors = operatingSystemMXBean.getAvailableProcessors();
long upTime = runtimeMXBean.getUptime();
double loadAverage = operatingSystemMXBean.getSystemLoadAverage();
log.info("Available processors: " + availableProcessors);
log.info("JVM upTime (ms): " + upTime);
log.info("CPU load average: " + loadAverage);
}
示例8: buildSystemLoadAverage
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
private static double buildSystemLoadAverage() {
// System load average for the last minute.
// The system load average is the sum of
// the number of runnable entities queued to the available processors
// and the number of runnable entities running on the available processors
// averaged over a period of time.
final OperatingSystemMXBean operatingSystem = ManagementFactory.getOperatingSystemMXBean();
if (operatingSystem.getSystemLoadAverage() >= 0) {
// systemLoadAverage n'existe qu'à partir du jdk 1.6
return operatingSystem.getSystemLoadAverage();
}
return -1;
}
示例9: sayHello
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
@Override
public String sayHello(final String queryString) {
final OperatingSystemMXBean osmxbean = ManagementFactory.getOperatingSystemMXBean();
final MemoryMXBean memxbean = ManagementFactory.getMemoryMXBean();
final double load = osmxbean.getSystemLoadAverage() / osmxbean.getAvailableProcessors();
final MemoryUsage mamUsage = memxbean.getHeapMemoryUsage();
final long maxMem = mamUsage.getMax();
final double usedmem = mamUsage.getUsed();
return String.join(",", "Hello there ", queryString, ". My CPU load is ", Double.toString(load), "my heap mem usage is ", Double.toString(usedmem / ((maxMem >= 0) ? maxMem : mamUsage.getCommitted())));
}
示例10: check
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
@Override
protected Result check() throws Exception {
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
double load = operatingSystemMXBean.getSystemLoadAverage();
int cpu = operatingSystemMXBean.getAvailableProcessors();
if (load < cpu) {
return Result.healthy();
} else {
return Result.unhealthy("load:%s,cpu:%s", load, cpu);
}
}
示例11: buildSystemLoadAverage
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
private double buildSystemLoadAverage() {
// System load average for the last minute.
// The system load average is the sum of
// the number of runnable entities queued to the available processors
// and the number of runnable entities running on the available processors
// averaged over a period of time.
OperatingSystemMXBean operatingSystem = ManagementFactory.getOperatingSystemMXBean();
if (operatingSystem.getSystemLoadAverage() >= 0) {
return operatingSystem.getSystemLoadAverage();
}
return -1;
}
示例12: getSystemLoadAverage
import java.lang.management.OperatingSystemMXBean; //導入方法依賴的package包/類
/** @return The current system load average if supported by the JDK.
* If it's not supported, the value will be negative. */
public static double getSystemLoadAverage() {
final OperatingSystemMXBean osBean =
ManagementFactory.getOperatingSystemMXBean();
return osBean.getSystemLoadAverage();
}