oshi.hardware.CentralProcessor.TickType Java Examples

The following examples show how to use oshi.hardware.CentralProcessor.TickType. 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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: CPUsDetailedPercConverter.java    From kieker with Apache License 2.0 5 votes vote down vote up
/**
 * @return the user utilization of the given core.
 */
public double getUserPerc() {
	if ((this.lastConversion == null) || (this.lastConversion.length == 0) || (this.lastConversion.length <= TickType.USER.getIndex())) {
		return 0;
	}
	return this.lastConversion[TickType.USER.getIndex()];
}
 
Example #16
Source File: CPUsDetailedPercConverter.java    From kieker with Apache License 2.0 5 votes vote down vote up
/**
 * @return the IRQ of the given core.
 */
public double getIrqPerc() {
	if ((this.lastConversion == null) || (this.lastConversion.length == 0) || (this.lastConversion.length <= TickType.IRQ.getIndex())
			|| (this.lastConversion.length <= TickType.SOFTIRQ.getIndex())) {
		return 0;
	}
	return this.lastConversion[TickType.IRQ.getIndex()] + this.lastConversion[TickType.SOFTIRQ.getIndex()];
}
 
Example #17
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 #18
Source File: CPUsDetailedPercConverter.java    From kieker with Apache License 2.0 5 votes vote down vote up
/**
 * @return the IDLE of the given core.
 */
public double getIdlePerc() {
	if ((this.lastConversion == null) || (this.lastConversion.length == 0) || (this.lastConversion.length <= TickType.IDLE.getIndex())) {
		return 0;
	}
	return this.lastConversion[TickType.IDLE.getIndex()];
}
 
Example #19
Source File: CPUsDetailedPercConverter.java    From kieker with Apache License 2.0 5 votes vote down vote up
/**
 * @return the combined utilization of the given core.
 */
public double getCombinedPerc() {
	if ((this.lastConversion == null) || (this.lastConversion.length == 0)) {
		return 0;
	}
	double combinedUsage = 0;
	for (int i = 0; i < this.lastConversion.length; i++) {
		if (i != TickType.IDLE.getIndex()) {
			combinedUsage = combinedUsage + this.lastConversion[i];
		}
	}
	return combinedUsage;
}
 
Example #20
Source File: CPUsDetailedPercConverter.java    From kieker with Apache License 2.0 5 votes vote down vote up
/**
 * @return the I/O wait of the given core.
 */
public double getWaitPerc() {
	if ((this.lastConversion == null) || (this.lastConversion.length == 0) || (this.lastConversion.length <= TickType.IOWAIT.getIndex())) {
		return 0;
	}
	return this.lastConversion[TickType.IOWAIT.getIndex()];
}
 
Example #21
Source File: CPUsDetailedPercConverter.java    From kieker with Apache License 2.0 5 votes vote down vote up
/**
 * @return the nice of the given core.
 */
public double getNicePerc() {
	if ((this.lastConversion == null) || (this.lastConversion.length == 0) || (this.lastConversion.length <= TickType.NICE.getIndex())) {
		return 0;
	}
	return this.lastConversion[TickType.NICE.getIndex()];
}
 
Example #22
Source File: CPUsDetailedPercConverter.java    From kieker with Apache License 2.0 5 votes vote down vote up
/**
 * @return the system utilization of the given core.
 */
public double getSystemPerc() {
	if ((this.lastConversion == null) || (this.lastConversion.length == 0) || (this.lastConversion.length <= TickType.SYSTEM.getIndex())) {
		return 0;
	}
	return this.lastConversion[TickType.SYSTEM.getIndex()];
}
 
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: 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 #25
Source File: RetrieveSystemDigest.java    From support-diagnostics with Apache License 2.0 4 votes vote down vote up
private static void printCpu(BufferedWriter writer, CentralProcessor processor) throws Exception {
    writer.write("CPU");
    writer.newLine();
    writer.write("---");
    writer.newLine();
    writer.write("Uptime: " + FormatUtil.formatElapsedSecs(processor.getSystemUptime()));
    writer.newLine();

    writer.write(
            "Context Switches/Interrupts: " + processor.getContextSwitches() + " / " + processor.getInterrupts());
    writer.newLine();


    long[] prevTicks = processor.getSystemCpuLoadTicks();

    writer.write("CPU, IOWait, and IRQ ticks @ 0 sec:" + Arrays.toString(prevTicks));
    writer.newLine();

    // Wait a second...
    Util.sleep(1000);
    long[] ticks = processor.getSystemCpuLoadTicks();

    writer.write("CPU, IOWait, and IRQ ticks @ 1 sec:" + Arrays.toString(ticks));
    writer.newLine();

    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long sys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.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 totalCpu = user + nice + sys + idle + iowait + irq + softirq + steal;

    writer.write(String.format(
            "User: %.1f%% Nice: %.1f%% System: %.1f%% Idle: %.1f%% IOwait: %.1f%% IRQ: %.1f%% SoftIRQ: %.1f%% Steal: %.1f%%%n",
            100d * user / totalCpu, 100d * nice / totalCpu, 100d * sys / totalCpu, 100d * idle / totalCpu,
            100d * iowait / totalCpu, 100d * irq / totalCpu, 100d * softirq / totalCpu, 100d * steal / totalCpu));
    writer.newLine();

    writer.write(String.format("CPU load: %.1f%% (counting ticks)%n", processor.getSystemCpuLoadBetweenTicks() * 100));
    writer.write(String.format("CPU load: %.1f%% (OS MXBean)%n", processor.getSystemCpuLoad() * 100));
    double[] loadAverage = processor.getSystemLoadAverage(3);
    writer.write("CPU load averages:" + (loadAverage[0] < 0 ? " N/A" : String.format(" %.2f", loadAverage[0]))
            + (loadAverage[1] < 0 ? " N/A" : String.format(" %.2f", loadAverage[1]))
            + (loadAverage[2] < 0 ? " N/A" : String.format(" %.2f", loadAverage[2])));
    // per core CPU
    StringBuilder procCpu = new StringBuilder("CPU load per processor:");
    double[] load = processor.getProcessorCpuLoadBetweenTicks();
    for (double avg : load) {
        procCpu.append(String.format(" %.1f%%", avg * 100));
    }
    writer.write(procCpu.toString());
    writer.newLine();

}
 
Example #26
Source File: SystemInfoTest.java    From javatech with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
private static void printCpu(CentralProcessor processor) {
    oshi.add("Context Switches/Interrupts: " + processor.getContextSwitches() + " / " + processor.getInterrupts());

    long[] prevTicks = processor.getSystemCpuLoadTicks();
    long[][] prevProcTicks = processor.getProcessorCpuLoadTicks();
    oshi.add("CPU, IOWait, and IRQ ticks @ 0 sec:" + Arrays.toString(prevTicks));
    // Wait a second...
    Util.sleep(1000);
    long[] ticks = processor.getSystemCpuLoadTicks();
    oshi.add("CPU, IOWait, and IRQ ticks @ 1 sec:" + Arrays.toString(ticks));
    long user = ticks[TickType.USER.getIndex()] - prevTicks[TickType.USER.getIndex()];
    long nice = ticks[TickType.NICE.getIndex()] - prevTicks[TickType.NICE.getIndex()];
    long sys = ticks[TickType.SYSTEM.getIndex()] - prevTicks[TickType.SYSTEM.getIndex()];
    long idle = ticks[TickType.IDLE.getIndex()] - prevTicks[TickType.IDLE.getIndex()];
    long iowait = ticks[TickType.IOWAIT.getIndex()] - prevTicks[TickType.IOWAIT.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 totalCpu = user + nice + sys + idle + iowait + irq + softirq + steal;

    oshi.add(String.format(
        "User: %.1f%% Nice: %.1f%% System: %.1f%% Idle: %.1f%% IOwait: %.1f%% IRQ: %.1f%% SoftIRQ: %.1f%% Steal: %.1f%%",
        100d * user / totalCpu, 100d * nice / totalCpu, 100d * sys / totalCpu, 100d * idle / totalCpu,
        100d * iowait / totalCpu, 100d * irq / totalCpu, 100d * softirq / totalCpu, 100d * steal / totalCpu));
    oshi.add(String.format("CPU load: %.1f%%", processor.getSystemCpuLoadBetweenTicks(prevTicks) * 100));
    double[] loadAverage = processor.getSystemLoadAverage(3);
    oshi.add("CPU load averages:" + (loadAverage[0] < 0 ? " N/A" : String.format(" %.2f", loadAverage[0]))
        + (loadAverage[1] < 0 ? " N/A" : String.format(" %.2f", loadAverage[1]))
        + (loadAverage[2] < 0 ? " N/A" : String.format(" %.2f", loadAverage[2])));
    // per core CPU
    StringBuilder procCpu = new StringBuilder("CPU load per processor:");
    double[] load = processor.getProcessorCpuLoadBetweenTicks(prevProcTicks);
    for (double avg : load) {
        procCpu.append(String.format(" %.1f%%", avg * 100));
    }
    oshi.add(procCpu.toString());
    long freq = processor.getProcessorIdentifier().getVendorFreq();
    if (freq > 0) {
        oshi.add("Vendor Frequency: " + FormatUtil.formatHertz(freq));
    }
    freq = processor.getMaxFreq();
    if (freq > 0) {
        oshi.add("Max Frequency: " + FormatUtil.formatHertz(freq));
    }
    long[] freqs = processor.getCurrentFreq();
    if (freqs[0] > 0) {
        StringBuilder sb = new StringBuilder("Current Frequencies: ");
        for (int i = 0; i < freqs.length; i++) {
            if (i > 0) {
                sb.append(", ");
            }
            sb.append(FormatUtil.formatHertz(freqs[i]));
        }
        oshi.add(sb.toString());
    }
}