oshi.hardware.CentralProcessor Java Examples

The following examples show how to use oshi.hardware.CentralProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OshiDevice.java    From iot-java with Eclipse Public License 1.0 7 votes vote down vote up
private static JsonObject createOshiData() {
	HardwareAbstractionLayer hal = si.getHardware();
	CentralProcessor processor = hal.getProcessor();
	double loadAverage = processor.getSystemCpuLoad() * 100;

	GlobalMemory memory = hal.getMemory();
	long availableMemory = memory.getAvailable();
	long totalMemory = memory.getTotal();
	long usedMemory = totalMemory - availableMemory;
	double memoryUtilization = (usedMemory / (double) totalMemory) * 100;

	JsonObject json = new JsonObject();
	json.addProperty("memory", memoryUtilization);
	json.addProperty("cpu", loadAverage);
	return json;
}
 
Example #2
Source File: Server.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor) {
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #3
Source File: OshiPlatformCache.java    From hawkular-agent with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the given metric's value, or null if there is no processor with the given number.
 *
 * @param processorNumber number of the processor, as a String
 * @param metricToCollect the metric to collect
 * @return the value of the metric, or null if there is no processor with the given number
 */
public Double getProcessorMetric(String processorNumber, ID metricToCollect) {

    CentralProcessor processor = getProcessor();
    if (processor == null) {
        return null;
    }

    int processorIndex;
    try {
        processorIndex = Integer.parseInt(processorNumber);
        if (processorIndex < 0 || processorIndex >= processor.getLogicalProcessorCount()) {
            return null;
        }
    } catch (Exception e) {
        return null;
    }

    if (PlatformMetricType.PROCESSOR_CPU_USAGE.getMetricTypeId().equals(metricToCollect)) {
        return processor.getProcessorCpuLoadBetweenTicks()[processorIndex];
    } else {
        throw new UnsupportedOperationException("Invalid processor metric to collect: " + metricToCollect);
    }
}
 
Example #4
Source File: CPUsCombinedPercSampler.java    From kieker with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void sample(final IMonitoringController monitoringController) {
	if (!monitoringController.isMonitoringEnabled() || !monitoringController.isProbeActivated(SignatureFactory.createCPUSignature())) {
		return;
	}
	final CentralProcessor centralProcessor = this.hardwareAbstractionLayer.getProcessor();
	final double[] cpuLoads = centralProcessor.getProcessorCpuLoadBetweenTicks();
	final ITimeSource timesource = monitoringController.getTimeSource();

	for (int i = 0; i < cpuLoads.length; i++) {
		if (monitoringController.isProbeActivated(SignatureFactory.createCPUSignature(i))) {

			final double combinedUtilization = cpuLoads[i];
			final ResourceUtilizationRecord r = new ResourceUtilizationRecord(timesource.getTime(),
					monitoringController.getHostname(), CPU_RESOURCE_NAME_PREFIX + i, combinedUtilization);
			monitoringController.newMonitoringRecord(r);
		}
	}
}
 
Example #5
Source File: Server.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor) {
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #6
Source File: SystemHardwareInfo.java    From Guns with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor) {
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #7
Source File: MonitorServiceImpl.java    From albedo with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取Cpu相关信息
 *
 * @param processor /
 * @return /
 */
private Map<String, Object> getCpuInfo(CentralProcessor processor) {
	Map<String, Object> cpuInfo = new LinkedHashMap<>();
	cpuInfo.put("name", processor.getProcessorIdentifier().getName());
	cpuInfo.put("package", processor.getPhysicalPackageCount() + "个物理CPU");
	cpuInfo.put("core", processor.getPhysicalProcessorCount() + "个物理核心");
	cpuInfo.put("coreNumber", processor.getPhysicalProcessorCount());
	cpuInfo.put("logic", processor.getLogicalProcessorCount() + "个逻辑CPU");
	// CPU信息
	long[] prevTicks = processor.getSystemCpuLoadTicks();
	// 等待1秒...
	Util.sleep(1000);
	long[] ticks = processor.getSystemCpuLoadTicks();
	long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()];
	long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()];
	long sys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
	long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
	long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
	long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()];
	long softirq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
	long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()];
	long totalCpu = user + nice + sys + idle + iowait + irq + softirq + steal;
	cpuInfo.put("used", df.format(100d * user / totalCpu + 100d * sys / totalCpu));
	cpuInfo.put("idle", df.format(100d * idle / totalCpu));
	return cpuInfo;
}
 
Example #8
Source File: Server.java    From boot-actuator with MIT License 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor)
{
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #9
Source File: Server.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor)
{
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #10
Source File: Server.java    From supplierShop with MIT License 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor)
{
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #11
Source File: Server.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor) {
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #12
Source File: Server.java    From Shiro-Action with MIT License 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor) {
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #13
Source File: ServerServiceImpl.java    From DimpleBlog with Apache License 2.0 6 votes vote down vote up
/**
 * 获取Cpu相关信息
 *
 * @param processor /
 * @return /
 */
private Map<String, Object> getCpuInfo(CentralProcessor processor) {
    Map<String, Object> cpuInfo = new LinkedHashMap<>();
    cpuInfo.put("name", processor.getProcessorIdentifier().getName());
    cpuInfo.put("package", processor.getPhysicalPackageCount() + "个物理CPU");
    cpuInfo.put("core", processor.getPhysicalProcessorCount() + "个物理核心");
    cpuInfo.put("coreNumber", processor.getPhysicalProcessorCount());
    cpuInfo.put("logic", processor.getLogicalProcessorCount() + "个逻辑CPU");
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    // 等待1秒...
    Util.sleep(1000);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()];
    long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()];
    long sys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
    long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
    long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
    long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()];
    long softirq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
    long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()];
    long totalCpu = user + nice + sys + idle + iowait + irq + softirq + steal;
    cpuInfo.put("used", df.format(100d * user / totalCpu + 100d * sys / totalCpu));
    cpuInfo.put("idle", df.format(100d * idle / totalCpu));
    return cpuInfo;
}
 
Example #14
Source File: Server.java    From LuckyFrameClient with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * ����CPU��Ϣ
 */
private void setCpuInfo(CentralProcessor processor)
{
    // CPU��Ϣ
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #15
Source File: MachineCpuStatistics.java    From garmadon with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
static void collectCpuTicks(long[] ticks, long[] prevTicks, StatisticsSink sink) {
    long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()];
    long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()];
    long sys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
    long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
    long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
    long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()];
    long softirq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
    long totalCpu = user + nice + sys + idle + iowait + irq + softirq;
    if (totalCpu > 0) {
        sink.addPercentage(CPU_VAR_USER, roundPercentage(user, totalCpu));
        sink.addPercentage(CPU_VAR_NICE, roundPercentage(nice, totalCpu));
        sink.addPercentage(CPU_VAR_SYS, roundPercentage(sys, totalCpu));
        sink.addPercentage(CPU_VAR_IDLE, roundPercentage(idle, totalCpu));
        sink.addPercentage(CPU_VAR_IOWAIT, roundPercentage(iowait, totalCpu));
        sink.addPercentage(CPU_VAR_IRQ, roundPercentage(irq, totalCpu));
        sink.addPercentage(CPU_VAR_SOFTIRQ, roundPercentage(softirq, totalCpu));
    }
}
 
Example #16
Source File: Server.java    From spring-boot-demo with MIT License 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor) {
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #17
Source File: Server.java    From NutzSite with Apache License 2.0 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor)
{
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #18
Source File: Server.java    From ruoyiplus with MIT License 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor)
{
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #19
Source File: Server.java    From RuoYi-Vue with MIT License 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor)
{
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    long softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    long steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    long cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;
    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(totalCpu);
    cpu.setSys(cSys);
    cpu.setUsed(user);
    cpu.setWait(iowait);
    cpu.setFree(idle);
}
 
Example #20
Source File: ServerInfo.java    From mogu_blog_v2 with Apache License 2.0 6 votes vote down vote up
/**
 * 设置CPU信息
 */
private void setCpuInfo(CentralProcessor processor)
{
    // CPU信息
    long[] prevTicks = processor.getSystemCpuLoadTicks();
    Util.sleep(OSHI_WAIT_SECOND);
    long[] ticks = processor.getSystemCpuLoadTicks();
    double nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    double irq = ticks[TickType.IRQ.getIndex()] - prevTicks[TickType.IRQ.getIndex()];
    double softirq = ticks[TickType.SOFTIRQ.getIndex()] - prevTicks[TickType.SOFTIRQ.getIndex()];
    double steal = ticks[TickType.STEAL.getIndex()] - prevTicks[TickType.STEAL.getIndex()];
    double cSys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    double user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    double iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.getIndex()];
    double idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    double totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;

    cpu.setCpuNum(processor.getLogicalProcessorCount());
    cpu.setTotal(Arith.round(Arith.mul(totalCpu, 100), 2));
    cpu.setSys(Arith.round(Arith.mul(user / totalCpu, 100), 2));
    cpu.setUsed(Arith.round(Arith.mul(cSys / totalCpu, 100), 2));
    cpu.setWait(Arith.round(Arith.mul(iowait / totalCpu, 100), 2));
    cpu.setFree(Arith.round(Arith.mul(idle / totalCpu, 100), 2));
}
 
Example #21
Source File: UsageStatisticsCollectorImpl.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
private void collectSystemStatistics(final @NotNull Statistic statistic) {

        if (!SYSTEM_METRICS_ENABLED) {
            return;
        }

        final OperatingSystem operatingSystem;
        final HardwareAbstractionLayer hardware;
        try {
            final SystemInfo systemInfo = new SystemInfo();
            operatingSystem = systemInfo.getOperatingSystem();
            hardware = systemInfo.getHardware();
        } catch (final UnsupportedOperationException e) {
            log.debug("system metrics are not supported, ignoring extended system information");
            log.trace("original exception", e);
            return;
        }

        statistic.setOsManufacturer(operatingSystem.getManufacturer());
        statistic.setOs(operatingSystem.getFamily());
        final OperatingSystemVersion version = operatingSystem.getVersion();
        statistic.setOsVersion(version.getVersion());
        statistic.setOpenFileLimit(operatingSystem.getFileSystem().getMaxFileDescriptors());

        //disk space in MB
        long totalDiskSpace = 0;
        for (final OSFileStore osFileStore : operatingSystem.getFileSystem().getFileStores()) {
            totalDiskSpace += (osFileStore.getTotalSpace() / 1024 / 1024);
        }
        statistic.setDiskSize(totalDiskSpace);

        final CentralProcessor processor = hardware.getProcessor();
        statistic.setCpu(processor.toString());
        statistic.setCpuSockets(processor.getPhysicalPackageCount());
        statistic.setCpuPhysicalCores(processor.getPhysicalProcessorCount());
        statistic.setCpuTotalCores(processor.getLogicalProcessorCount());

        statistic.setOsUptime(processor.getSystemUptime());
        statistic.setMemorySize(hardware.getMemory().getTotal() / 1024 / 1024);
    }
 
Example #22
Source File: CPULoadCollector.java    From Mycat2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public List<MetricFamilySamples> collect() {
        SystemInfo systemInfo = new SystemInfo();
        CentralProcessor processor = systemInfo.getHardware().getProcessor();
//        List<CentralProcessor.LogicalProcessor> logicalProcessors = processor.getLogicalProcessors();
        long[][] pTickList = processor.getProcessorCpuLoadTicks();

        GaugeMetricFamily gaugeMetricFamily = new GaugeMetricFamily("mycat_cpu_utility", "mycat_cpu_utility", ImmutableList.of("index"));

        long[][] tickList = processor.getProcessorCpuLoadTicks();
        for (int i = 0; i < pTickList.length; i++) {
            long[] prevTicks = pTickList[i];
            long[] ticks = tickList[i];

            long nice = ticks[CentralProcessor.TickType.NICE.getIndex()] - prevTicks[CentralProcessor.TickType.NICE.getIndex()];
            long irq = ticks[CentralProcessor.TickType.IRQ.getIndex()] - prevTicks[CentralProcessor.TickType.IRQ.getIndex()];
            long softirq = ticks[CentralProcessor.TickType.SOFTIRQ.getIndex()] - prevTicks[CentralProcessor.TickType.SOFTIRQ.getIndex()];
            long steal = ticks[CentralProcessor.TickType.STEAL.getIndex()] - prevTicks[CentralProcessor.TickType.STEAL.getIndex()];
            long cSys = ticks[CentralProcessor.TickType.SYSTEM.getIndex()] - prevTicks[CentralProcessor.TickType.SYSTEM.getIndex()];
            long user = ticks[CentralProcessor.TickType.USER.getIndex()] - prevTicks[CentralProcessor.TickType.USER.getIndex()];
            long iowait = ticks[CentralProcessor.TickType.IOWAIT.getIndex()] - prevTicks[CentralProcessor.TickType.IOWAIT.getIndex()];
            long idle = ticks[CentralProcessor.TickType.IDLE.getIndex()] - prevTicks[CentralProcessor.TickType.IDLE.getIndex()];
            long totalCpu = user + nice + cSys + idle + iowait + irq + softirq + steal;

            double utility  = 1.0 - (idle * 1.0 / totalCpu);
            if (!Double.isInfinite(utility)) {
                utility = 0;
            }
            gaugeMetricFamily.addMetric(ImmutableList.of(String.valueOf(i)),utility);

        }




        return ImmutableList.of(gaugeMetricFamily);
    }
 
Example #23
Source File: SystemResourcesCounter.java    From flink with Apache License 2.0 5 votes vote down vote up
private void calculateCPUUsage(CentralProcessor processor) {
	long[] ticks = processor.getSystemCpuLoadTicks();
	if (this.previousCpuTicks == null) {
		this.previousCpuTicks = ticks;
	}

	long userTicks = ticks[TickType.USER.getIndex()] - previousCpuTicks[TickType.USER.getIndex()];
	long niceTicks = ticks[TickType.NICE.getIndex()] - previousCpuTicks[TickType.NICE.getIndex()];
	long sysTicks = ticks[TickType.SYSTEM.getIndex()] - previousCpuTicks[TickType.SYSTEM.getIndex()];
	long idleTicks = ticks[TickType.IDLE.getIndex()] - previousCpuTicks[TickType.IDLE.getIndex()];
	long iowaitTicks = ticks[TickType.IOWAIT.getIndex()] - previousCpuTicks[TickType.IOWAIT.getIndex()];
	long irqTicks = ticks[TickType.IRQ.getIndex()] - previousCpuTicks[TickType.IRQ.getIndex()];
	long softIrqTicks = ticks[TickType.SOFTIRQ.getIndex()] - previousCpuTicks[TickType.SOFTIRQ.getIndex()];
	long totalCpuTicks = userTicks + niceTicks + sysTicks + idleTicks + iowaitTicks + irqTicks + softIrqTicks;
	this.previousCpuTicks = ticks;

	cpuUser = 100d * userTicks / totalCpuTicks;
	cpuNice = 100d * niceTicks / totalCpuTicks;
	cpuSys = 100d * sysTicks / totalCpuTicks;
	cpuIdle = 100d * idleTicks / totalCpuTicks;
	cpuIOWait = 100d * iowaitTicks / totalCpuTicks;
	cpuIrq = 100d * irqTicks / totalCpuTicks;
	cpuSoftIrq = 100d * softIrqTicks / totalCpuTicks;

	cpuUsage = processor.getSystemCpuLoad() * 100;

	double[] loadAverage = processor.getSystemLoadAverage(3);
	cpuLoad1 = (loadAverage[0] < 0 ? Double.NaN : loadAverage[0]);
	cpuLoad5 = (loadAverage[1] < 0 ? Double.NaN : loadAverage[1]);
	cpuLoad15 = (loadAverage[2] < 0 ? Double.NaN : loadAverage[2]);

	double[] load = processor.getProcessorCpuLoadBetweenTicks();
	checkState(load.length == cpuUsagePerProcessor.length());
	for (int i = 0; i < load.length; i++) {
		cpuUsagePerProcessor.set(i, load[i] * 100);
	}
}
 
Example #24
Source File: CPUsDetailedPercSampler.java    From kieker with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void sample(final IMonitoringController monitoringController) {
	if (!monitoringController.isMonitoringEnabled() || !monitoringController.isProbeActivated(SignatureFactory.createCPUSignature())) {
		return;
	}
	final CentralProcessor centralProcessor = this.hardwareAbstractionLayer.getProcessor();
	final long[][] processorLoadTicks = centralProcessor.getProcessorCpuLoadTicks();
	if (this.converters == null) {
		this.converters = new CPUsDetailedPercConverter[processorLoadTicks.length];
		for (int i = 0; i < this.converters.length; i++) {
			this.converters[i] = new CPUsDetailedPercConverter(i);
		}
	}
	final ITimeSource timesource = monitoringController.getTimeSource();
	for (int i = 0; i < processorLoadTicks.length; i++) {
		if (monitoringController.isProbeActivated(SignatureFactory.createCPUSignature(i))) {
			final CPUsDetailedPercConverter converter = this.converters[i];
			final long[] plt = processorLoadTicks[i];
			converter.passNewProcessorLoadTicks(plt);
			converter.convertToPercentage();

			final double system = converter.getSystemPerc();
			final double wait = converter.getWaitPerc();
			final double nice = converter.getNicePerc();
			final double idle = converter.getIdlePerc();
			final double user = converter.getUserPerc();
			final double irq = converter.getIrqPerc();
			final double combined = centralProcessor.getProcessorCpuLoadBetweenTicks()[i];

			final CPUUtilizationRecord r = new CPUUtilizationRecord(timesource.getTime(),
					monitoringController.getHostname(), Integer.toString(i), user, system, wait, nice, irq,
					combined, idle);
			monitoringController.newMonitoringRecord(r);
		}
	}
}
 
Example #25
Source File: SystemResourcesCounter.java    From flink with Apache License 2.0 5 votes vote down vote up
private void calculateCPUUsage(CentralProcessor processor) {
	long[] ticks = processor.getSystemCpuLoadTicks();
	if (this.previousCpuTicks == null) {
		this.previousCpuTicks = ticks;
	}

	long userTicks = ticks[TickType.USER.getIndex()] - previousCpuTicks[TickType.USER.getIndex()];
	long niceTicks = ticks[TickType.NICE.getIndex()] - previousCpuTicks[TickType.NICE.getIndex()];
	long sysTicks = ticks[TickType.SYSTEM.getIndex()] - previousCpuTicks[TickType.SYSTEM.getIndex()];
	long idleTicks = ticks[TickType.IDLE.getIndex()] - previousCpuTicks[TickType.IDLE.getIndex()];
	long iowaitTicks = ticks[TickType.IOWAIT.getIndex()] - previousCpuTicks[TickType.IOWAIT.getIndex()];
	long irqTicks = ticks[TickType.IRQ.getIndex()] - previousCpuTicks[TickType.IRQ.getIndex()];
	long softIrqTicks = ticks[TickType.SOFTIRQ.getIndex()] - previousCpuTicks[TickType.SOFTIRQ.getIndex()];
	long totalCpuTicks = userTicks + niceTicks + sysTicks + idleTicks + iowaitTicks + irqTicks + softIrqTicks;
	this.previousCpuTicks = ticks;

	cpuUser = 100d * userTicks / totalCpuTicks;
	cpuNice = 100d * niceTicks / totalCpuTicks;
	cpuSys = 100d * sysTicks / totalCpuTicks;
	cpuIdle = 100d * idleTicks / totalCpuTicks;
	cpuIOWait = 100d * iowaitTicks / totalCpuTicks;
	cpuIrq = 100d * irqTicks / totalCpuTicks;
	cpuSoftIrq = 100d * softIrqTicks / totalCpuTicks;

	cpuUsage = processor.getSystemCpuLoad() * 100;

	double[] loadAverage = processor.getSystemLoadAverage(3);
	cpuLoad1 = (loadAverage[0] < 0 ? Double.NaN : loadAverage[0]);
	cpuLoad5 = (loadAverage[1] < 0 ? Double.NaN : loadAverage[1]);
	cpuLoad15 = (loadAverage[2] < 0 ? Double.NaN : loadAverage[2]);

	double[] load = processor.getProcessorCpuLoadBetweenTicks();
	checkState(load.length == cpuUsagePerProcessor.length());
	for (int i = 0; i < load.length; i++) {
		cpuUsagePerProcessor.set(i, load[i] * 100);
	}
}
 
Example #26
Source File: SystemResourcesCounter.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private void calculateCPUUsage(CentralProcessor processor) {
	long[] ticks = processor.getSystemCpuLoadTicks();
	if (this.previousCpuTicks == null) {
		this.previousCpuTicks = ticks;
	}

	long userTicks = ticks[TickType.USER.getIndex()] - previousCpuTicks[TickType.USER.getIndex()];
	long niceTicks = ticks[TickType.NICE.getIndex()] - previousCpuTicks[TickType.NICE.getIndex()];
	long sysTicks = ticks[TickType.SYSTEM.getIndex()] - previousCpuTicks[TickType.SYSTEM.getIndex()];
	long idleTicks = ticks[TickType.IDLE.getIndex()] - previousCpuTicks[TickType.IDLE.getIndex()];
	long iowaitTicks = ticks[TickType.IOWAIT.getIndex()] - previousCpuTicks[TickType.IOWAIT.getIndex()];
	long irqTicks = ticks[TickType.IRQ.getIndex()] - previousCpuTicks[TickType.IRQ.getIndex()];
	long softIrqTicks = ticks[TickType.SOFTIRQ.getIndex()] - previousCpuTicks[TickType.SOFTIRQ.getIndex()];
	long totalCpuTicks = userTicks + niceTicks + sysTicks + idleTicks + iowaitTicks + irqTicks + softIrqTicks;
	this.previousCpuTicks = ticks;

	cpuUser = 100d * userTicks / totalCpuTicks;
	cpuNice = 100d * niceTicks / totalCpuTicks;
	cpuSys = 100d * sysTicks / totalCpuTicks;
	cpuIdle = 100d * idleTicks / totalCpuTicks;
	cpuIOWait = 100d * iowaitTicks / totalCpuTicks;
	cpuIrq = 100d * irqTicks / totalCpuTicks;
	cpuSoftIrq = 100d * softIrqTicks / totalCpuTicks;

	cpuUsage = processor.getSystemCpuLoad() * 100;

	double[] loadAverage = processor.getSystemLoadAverage(3);
	cpuLoad1 = (loadAverage[0] < 0 ? Double.NaN : loadAverage[0]);
	cpuLoad5 = (loadAverage[1] < 0 ? Double.NaN : loadAverage[1]);
	cpuLoad15 = (loadAverage[2] < 0 ? Double.NaN : loadAverage[2]);

	double[] load = processor.getProcessorCpuLoadBetweenTicks();
	checkState(load.length == cpuUsagePerProcessor.length());
	for (int i = 0; i < load.length; i++) {
		cpuUsagePerProcessor.set(i, load[i] * 100);
	}
}
 
Example #27
Source File: EnvironmentCommand.java    From LagMonitor with MIT License 4 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!canExecute(sender, command)) {
        return true;
    }

    OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();

    //os general info
    sendMessage(sender, "OS Name", osBean.getName());
    sendMessage(sender, "OS Arch", osBean.getArch());

    Optional<SystemInfo> optInfo = plugin.getNativeData().getSystemInfo();
    if (optInfo.isPresent()) {
        SystemInfo systemInfo = optInfo.get();

        OperatingSystem osInfo = systemInfo.getOperatingSystem();
        sendMessage(sender, "OS family", osInfo.getFamily());
        sendMessage(sender, "OS version", osInfo.getVersionInfo().toString());
        sendMessage(sender, "OS Manufacturer", osInfo.getManufacturer());

        sendMessage(sender, "Total processes", String.valueOf(osInfo.getProcessCount()));
        sendMessage(sender, "Total threads", String.valueOf(osInfo.getThreadCount()));
    }

    //CPU
    sender.sendMessage(PRIMARY_COLOR + "CPU:");
    if (optInfo.isPresent()) {
        CentralProcessor processor = optInfo.get().getHardware().getProcessor();
        ProcessorIdentifier identifier = processor.getProcessorIdentifier();

        sendMessage(sender, "    Vendor", identifier.getVendor());
        sendMessage(sender, "    Family", identifier.getFamily());
        sendMessage(sender, "    Name", identifier.getName());
        sendMessage(sender, "    Model", identifier.getModel());
        sendMessage(sender, "    Id", identifier.getIdentifier());
        sendMessage(sender, "    Vendor freq", String.valueOf(identifier.getVendorFreq()));
        sendMessage(sender, "    Physical Cores", String.valueOf(processor.getPhysicalProcessorCount()));
    }

    sendMessage(sender, "    Logical Cores", String.valueOf(osBean.getAvailableProcessors()));
    sendMessage(sender, "    Endian", System.getProperty("sun.cpu.endian", "Unknown"));

    sendMessage(sender, "Load Average", String.valueOf(osBean.getSystemLoadAverage()));
    printExtendOsInfo(sender);

    displayDiskSpace(sender);

    NativeManager nativeData = plugin.getNativeData();
    sendMessage(sender, "Open file descriptors", String.valueOf(nativeData.getOpenFileDescriptors()));
    sendMessage(sender, "Max file descriptors", String.valueOf(nativeData.getMaxFileDescriptors()));

    sender.sendMessage(PRIMARY_COLOR + "Variables:");
    for (Entry<String, String> variable : System.getenv().entrySet()) {
        sendMessage(sender, "    " + variable.getKey(), variable.getValue());
    }

    return true;
}
 
Example #28
Source File: EnvironmentCommand.java    From LagMonitor with MIT License 4 votes vote down vote up
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!canExecute(sender, command)) {
        return true;
    }

    OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();

    //os general info
    sendMessage(sender, "OS Name", osBean.getName());
    sendMessage(sender, "OS Arch", osBean.getArch());

    Optional<SystemInfo> optInfo = plugin.getNativeData().getSystemInfo();
    if (optInfo.isPresent()) {
        SystemInfo systemInfo = optInfo.get();

        OperatingSystem osInfo = systemInfo.getOperatingSystem();
        sendMessage(sender, "OS family", osInfo.getFamily());
        sendMessage(sender, "OS version", osInfo.getVersionInfo().toString());
        sendMessage(sender, "OS Manufacturer", osInfo.getManufacturer());

        sendMessage(sender, "Total processes", String.valueOf(osInfo.getProcessCount()));
        sendMessage(sender, "Total threads", String.valueOf(osInfo.getThreadCount()));
    }

    //CPU
    sender.sendMessage(PRIMARY_COLOR + "CPU:");
    if (optInfo.isPresent()) {
        CentralProcessor processor = optInfo.get().getHardware().getProcessor();
        ProcessorIdentifier identifier = processor.getProcessorIdentifier();

        sendMessage(sender, "    Vendor", identifier.getVendor());
        sendMessage(sender, "    Family", identifier.getFamily());
        sendMessage(sender, "    Name", identifier.getName());
        sendMessage(sender, "    Model", identifier.getModel());
        sendMessage(sender, "    Id", identifier.getIdentifier());
        sendMessage(sender, "    Vendor freq", String.valueOf(identifier.getVendorFreq()));
        sendMessage(sender, "    Physical Cores", String.valueOf(processor.getPhysicalProcessorCount()));
    }

    sendMessage(sender, "    Logical Cores", String.valueOf(osBean.getAvailableProcessors()));
    sendMessage(sender, "    Endian", System.getProperty("sun.cpu.endian", "Unknown"));

    sendMessage(sender, "Load Average", String.valueOf(osBean.getSystemLoadAverage()));
    printExtendOsInfo(sender);

    displayDiskSpace(sender);

    NativeManager nativeData = plugin.getNativeData();
    sendMessage(sender, "Open file descriptors", String.valueOf(nativeData.getOpenFileDescriptors()));
    sendMessage(sender, "Max file descriptors", String.valueOf(nativeData.getMaxFileDescriptors()));

    sender.sendMessage(PRIMARY_COLOR + "Variables:");
    for (Entry<String, String> variable : System.getenv().entrySet()) {
        sendMessage(sender, "    " + variable.getKey(), variable.getValue());
    }

    return true;
}