當前位置: 首頁>>代碼示例>>Java>>正文


Java OperatingSystemMXBean.getSystemLoadAverage方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:games647,項目名稱:Java-Snippets,代碼行數:18,代碼來源:EnvironmentInfo.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:25,代碼來源:MetricsServoRegistry.java

示例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);
    }
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:19,代碼來源:ProcessorMetrics.java

示例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;
}
 
開發者ID:Wolfgang-Winter,項目名稱:cibet,代碼行數:24,代碼來源:VMLoadControlJMXBean.java

示例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;
   }
}
 
開發者ID:Wolfgang-Winter,項目名稱:cibet,代碼行數:19,代碼來源:VMLoadControlJMXBean.java

示例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();

}
 
開發者ID:ParkJinSang,項目名稱:Jinseng-Server,代碼行數:14,代碼來源:ServerStatus.java

示例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);
}
 
開發者ID:omerio,項目名稱:ecarf,代碼行數:14,代碼來源:Utils.java

示例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;
}
 
開發者ID:javamelody,項目名稱:javamelody,代碼行數:14,代碼來源:JavaInformations.java

示例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())));
}
 
開發者ID:whalebone,項目名稱:sinkit-core,代碼行數:11,代碼來源:WebApiEJB.java

示例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);
	}
	
}
 
開發者ID:cqyijifu,項目名稱:watcher,代碼行數:13,代碼來源:SystemLoadHealthCheck.java

示例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;
}
 
開發者ID:gitblit,項目名稱:sysinfo,代碼行數:13,代碼來源:SysInfo.java

示例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();
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:8,代碼來源:Utils.java


注:本文中的java.lang.management.OperatingSystemMXBean.getSystemLoadAverage方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。