java.lang.management.OperatingSystemMXBean#getAvailableProcessors ( )源码实例Demo

下面列出了java.lang.management.OperatingSystemMXBean#getAvailableProcessors ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dubbo-2.6.5   文件: LoadStatusChecker.java
@Override
public Status check() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    double load;
    try {
        Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
        load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
        if (load == -1) {
            com.sun.management.OperatingSystemMXBean bean =
                    (com.sun.management.OperatingSystemMXBean) operatingSystemMXBean;
            load = bean.getSystemCpuLoad();
        }
    } catch (Throwable e) {
        load = -1;
    }
    int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN),
            (load < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
 
源代码2 项目: visualvm   文件: CpuMonitorProbe.java
CpuMonitorProbe(MonitoredDataResolver resolver, Application application,
                Jvm jvm) {
    super(2, createItemDescriptors(), resolver);
    cpuSupported = jvm.isCpuMonitoringSupported();
    gcSupported = jvm.isCollectionTimeSupported();
    int pCount = 1;
    JmxModel jmxModel = JmxModelFactory.getJmxModelFor(application);
    if (jmxModel != null && jmxModel.getConnectionState() == ConnectionState.CONNECTED) {
        JvmMXBeans mxbeans = JvmMXBeansFactory.getJvmMXBeans(jmxModel);
        if (mxbeans != null) {
            OperatingSystemMXBean osbean = mxbeans.getOperatingSystemMXBean();
            if (osbean != null) pCount = osbean.getAvailableProcessors();
        }
    }
    processorsCount = pCount;
}
 
public Status check() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    double load;
    try {
        Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
        load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
    } catch (Throwable e) {
        load = -1;
    }
    int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
 
源代码4 项目: dubbox   文件: LoadStatusChecker.java
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
 
源代码5 项目: dubbox   文件: LoadStatusChecker.java
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), (load < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
 
源代码6 项目: dubbox   文件: LoadStatusChecker.java
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
 
源代码7 项目: dubbox-hystrix   文件: LoadStatusChecker.java
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), (load < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
 
源代码8 项目: dubbox-hystrix   文件: LoadStatusChecker.java
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
 
源代码9 项目: nifi   文件: DiagnosticAnalysisTask.java
private void analyzeCpuUsage(final List<String> details) {
    final OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();

    final double loadAverage = os.getSystemLoadAverage();
    final int availableProcs = os.getAvailableProcessors();

    if (loadAverage > availableProcs) {
        details.add(String.format("1-minute CPU Load Average is %1$.2f, which exceeds the %2$d available cores. CPU is over-utilized.", loadAverage, availableProcs));
    } else if (loadAverage > 0.9 * availableProcs) {
        details.add(String.format("1-minute CPU Load Average is %1$.2f, which exceeds 90%% of the %2$d available cores. CPU may struggle to keep up.", loadAverage, availableProcs));
    }
}
 
源代码10 项目: neural   文件: OperatingSystemMetrice.java
/**
 * 系统平均负载(满负荷状态为1.00*CPU核数)
 */
public Double getData() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    double load;
    try {
        Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage");
        load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
    } catch (Throwable e) {
        load = -1;
    }
    int cpu = operatingSystemMXBean.getAvailableProcessors();
    return Double.valueOf(String.format("%.4f", load / cpu));
}
 
源代码11 项目: rtg-tools   文件: Environment.java
/**
 * Get number of available processors.
 * @return number of available processors.
 */
public static int getAvailableProcessors() {
  final OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
  if (bean != null) {
    return bean.getAvailableProcessors();
  }
  throw new IllegalStateException();
}
 
源代码12 项目: visualvm   文件: JmxSupport.java
int getAvailableProcessors() {
    JvmMXBeans jmx = getJvmMXBeans();
    if (jmx != null) {
        OperatingSystemMXBean osMXBean = jmx.getOperatingSystemMXBean();

        if (osMXBean != null) {
            return osMXBean.getAvailableProcessors();
        }
    }
    return -1;
}
 
源代码13 项目: dubbo3   文件: LoadStatusChecker.java
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage");
	    load = (Double)method.invoke(operatingSystemMXBean);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), (load < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
 
源代码14 项目: dubbox   文件: LoadStatusChecker.java
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
 
源代码15 项目: dubbox   文件: LoadStatusChecker.java
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), (load < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
 
源代码16 项目: dubbox   文件: LoadStatusChecker.java
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
 
源代码17 项目: dubbox   文件: LoadStatusChecker.java
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
 
源代码18 项目: watcher   文件: SystemLoadHealthCheck.java
@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);
	}
	
}
 
源代码19 项目: incubator-retired-blur   文件: ThriftServer.java
public static void setupJvmMetrics() {
  final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
  final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();

  Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, SYSTEM, LOAD_AVERAGE), new Gauge<Double>() {
    @Override
    public Double value() {
      return operatingSystemMXBean.getSystemLoadAverage();
    }
  });
  Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, JVM, HEAP_USED), new Gauge<Long>() {
    @Override
    public Long value() {
      MemoryUsage usage = memoryMXBean.getHeapMemoryUsage();
      return usage.getUsed();
    }
  });
  Method processCpuTimeMethod = null;
  for (Method method : operatingSystemMXBean.getClass().getDeclaredMethods()) {
    if (method.getName().equals("getProcessCpuTime")) {
      method.setAccessible(true);
      processCpuTimeMethod = method;
    }
  }
  final double availableProcessors = operatingSystemMXBean.getAvailableProcessors();
  if (processCpuTimeMethod != null) {
    final Method pctm = processCpuTimeMethod;
    Metrics.newGauge(new MetricName(ORG_APACHE_BLUR, JVM, CPU_USED), new Gauge<Double>() {
      private long start = System.nanoTime();
      private long lastCpuTime = getProcessCputTime(pctm, operatingSystemMXBean);

      @Override
      public Double value() {
        long now = System.nanoTime();
        long cpuTime = getProcessCputTime(pctm, operatingSystemMXBean);
        long time = now - start;
        long processTime = cpuTime - lastCpuTime;
        try {
          return ((processTime / (double) time) / availableProcessors) * 100.0;
        } finally {
          lastCpuTime = cpuTime;
          start = System.nanoTime();
        }
      }
    });
  }
}
 
源代码20 项目: database   文件: MacOSX.java
public MacOSX()
{
	final OperatingSystemMXBean b = ManagementFactory.getOperatingSystemMXBean();

	m_processors = b.getAvailableProcessors();
	
	m_cpuInfo = b.getName()+" "+b.getVersion()+" "+b.getArch();

}