命名Review

v1.4.1
Parker 4 years ago
parent b9b4bfbf6a
commit f9843ecd2f

@ -6,6 +6,7 @@ package org.opsli.core.monitor;
import cn.hutool.core.net.NetUtil;
import cn.hutool.core.util.NumberUtil;
import com.google.common.collect.Lists;
import lombok.Data;
import org.opsli.core.monitor.utils.*;
import oshi.SystemInfo;
@ -18,7 +19,6 @@ import oshi.software.os.OperatingSystem;
import oshi.util.Util;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
/**
@ -28,8 +28,10 @@ import java.util.Properties;
*/
@Data
public class SystemHardwareInfo implements Serializable {
private static final long serialVersionUID = 1L;
/** 监控等待时间 */
private static final int OSHI_WAIT_SECOND = 1000;
/**
@ -55,7 +57,7 @@ public class SystemHardwareInfo implements Serializable {
/**
*
*/
private List<SysFile> sysFiles = new LinkedList<SysFile>();
private List<SysFile> sysFiles = Lists.newLinkedList();
public void copyTo() throws Exception {
@ -74,26 +76,26 @@ public class SystemHardwareInfo implements Serializable {
}
public void copyToCupInof() throws Exception {
public void copyToCupInfo() throws Exception {
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
setCpuInfo(hal.getProcessor());
}
public void copyToMemInof() throws Exception {
public void copyToMemInfo() throws Exception {
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
setMemInfo(hal.getMemory());
}
public void copyToSysInof() throws Exception {
public void copyToSysInfo() throws Exception {
SystemInfo si = new SystemInfo();
setSysInfo(si.getOperatingSystem());
}
public void copyToJvmInof() throws Exception {
public void copyToJvmInfo() throws Exception {
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
setJvmInfo();
}
public void copyToSysFilesInof() throws Exception {
public void copyToSysFilesInfo() throws Exception {
SystemInfo si = new SystemInfo();
setSysFiles(si.getOperatingSystem());
}
@ -106,23 +108,26 @@ public class SystemHardwareInfo implements Serializable {
private void setCpuInfo(CentralProcessor processor) {
// CPU信息
long[] prevTicks = processor.getSystemCpuLoadTicks();
// OSHI 等待睡眠
Util.sleep(OSHI_WAIT_SECOND);
long[] ticks = processor.getSystemCpuLoadTicks();
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 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 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;
long totalCpu = user + nice + cSys + idle + ioWait + irq + softIrq + steal;
cpu.setCpuNum(processor.getLogicalProcessorCount());
cpu.setCpuName(processor.getName());
cpu.setTotal(totalCpu);
cpu.setSys(cSys);
cpu.setUsed(user);
cpu.setWait(iowait);
cpu.setWait(ioWait);
cpu.setFree(idle);
}

@ -15,6 +15,7 @@ import java.io.Serializable;
*/
@Data
public class CPU implements Serializable {
private static final long serialVersionUID = 1L;
/**
@ -51,6 +52,8 @@ public class CPU implements Serializable {
*/
private double free;
// =================
public double getTotal() {
return NumberUtil.round(NumberUtil.mul(total, 100), 2).doubleValue();
}

@ -19,6 +19,7 @@ import java.util.Date;
*/
@Data
public class JVM implements Serializable {
private static final long serialVersionUID = 1L;
/**
@ -98,12 +99,13 @@ public class JVM implements Serializable {
public double getUsage() {
return NumberUtil.mul(NumberUtil.div(total - free, total, 4), 100);
}
/**
* JDK
*/
public String getName() {
return ManagementFactory.getRuntimeMXBean().getVmName();
}/**
}
/**

@ -15,6 +15,7 @@ import java.io.Serializable;
*/
@Data
public class Mem implements Serializable {
private static final long serialVersionUID = 1L;
/**

@ -14,6 +14,7 @@ import java.io.Serializable;
*/
@Data
public class Sys implements Serializable {
private static final long serialVersionUID = 1L;
/**

@ -14,6 +14,7 @@ import java.io.Serializable;
*/
@Data
public class SysFile implements Serializable {
private static final long serialVersionUID = 1L;
/**

@ -27,7 +27,7 @@ public class MonitorServiceImpl implements IMonitorService {
@Override
public Sys getSysInfo() throws Exception {
SystemHardwareInfo systemHardwareInfo = new SystemHardwareInfo();
systemHardwareInfo.copyToSysInof();
systemHardwareInfo.copyToSysInfo();
return systemHardwareInfo.getSys();
}
@ -41,28 +41,28 @@ public class MonitorServiceImpl implements IMonitorService {
@Override
public CPU getCpuInfo() throws Exception {
SystemHardwareInfo systemHardwareInfo = new SystemHardwareInfo();
systemHardwareInfo.copyToCupInof();
systemHardwareInfo.copyToCupInfo();
return systemHardwareInfo.getCpu();
}
@Override
public Mem getMemInfo() throws Exception {
SystemHardwareInfo systemHardwareInfo = new SystemHardwareInfo();
systemHardwareInfo.copyToMemInof();
systemHardwareInfo.copyToMemInfo();
return systemHardwareInfo.getMem();
}
@Override
public JVM getJVMInfo() throws Exception {
SystemHardwareInfo systemHardwareInfo = new SystemHardwareInfo();
systemHardwareInfo.copyToJvmInof();
systemHardwareInfo.copyToJvmInfo();
return systemHardwareInfo.getJvm();
}
@Override
public List<SysFile> getSysFiles() throws Exception {
SystemHardwareInfo systemHardwareInfo = new SystemHardwareInfo();
systemHardwareInfo.copyToSysFilesInof();
systemHardwareInfo.copyToSysFilesInfo();
return systemHardwareInfo.getSysFiles();
}

@ -23,7 +23,7 @@ import java.util.Map;
*/
@Slf4j
@ApiRestController("/sys/monitor")
public class monitorController {
public class MonitorController {
@Autowired
private IMonitorService monitorService;
Loading…
Cancel
Save