mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-18 04:28:40 +00:00
增加osutil 取操作系统名称,cpu型号,cpu核心数方法
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
package com.zfoo.monitor.model;
|
||||
|
||||
import com.baidu.bjf.remoting.protobuf.annotation.Protobuf;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class SystemInfoVo {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* host名称
|
||||
*/
|
||||
private String hostname;
|
||||
|
||||
/**
|
||||
* 系统版本信息
|
||||
*/
|
||||
private String version;
|
||||
|
||||
/**
|
||||
* 系统版本详细信息
|
||||
*/
|
||||
private String versionDetail;
|
||||
|
||||
/**
|
||||
* 内存使用率
|
||||
*/
|
||||
private Double memPer;
|
||||
|
||||
/**
|
||||
* core的个数(即核数)
|
||||
*/
|
||||
private String cpuCoreNum;
|
||||
|
||||
/**
|
||||
* cpu使用率
|
||||
*/
|
||||
private Double cpuPer;
|
||||
|
||||
/**
|
||||
* CPU型号信息
|
||||
*/
|
||||
private String cpuXh;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
|
||||
public String getHostname() {
|
||||
return hostname;
|
||||
}
|
||||
|
||||
public void setHostname(String hostname) {
|
||||
this.hostname = hostname;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getVersionDetail() {
|
||||
return versionDetail;
|
||||
}
|
||||
|
||||
public void setVersionDetail(String versionDetail) {
|
||||
this.versionDetail = versionDetail;
|
||||
}
|
||||
|
||||
public Double getMemPer() {
|
||||
return memPer;
|
||||
}
|
||||
|
||||
public void setMemPer(Double memPer) {
|
||||
this.memPer = memPer;
|
||||
}
|
||||
|
||||
public String getCpuCoreNum() {
|
||||
return cpuCoreNum;
|
||||
}
|
||||
|
||||
public void setCpuCoreNum(String cpuCoreNum) {
|
||||
this.cpuCoreNum = cpuCoreNum;
|
||||
}
|
||||
|
||||
public Double getCpuPer() {
|
||||
return cpuPer;
|
||||
}
|
||||
|
||||
public void setCpuPer(Double cpuPer) {
|
||||
this.cpuPer = cpuPer;
|
||||
}
|
||||
|
||||
public String getCpuXh() {
|
||||
return cpuXh;
|
||||
}
|
||||
|
||||
public void setCpuXh(String cpuXh) {
|
||||
this.cpuXh = cpuXh;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
@@ -17,10 +17,12 @@ import com.zfoo.monitor.model.*;
|
||||
import com.zfoo.protocol.util.IOUtils;
|
||||
import com.zfoo.protocol.util.StringUtils;
|
||||
import com.zfoo.scheduler.util.TimeUtils;
|
||||
import com.zfoo.util.net.NetUtils;
|
||||
import com.zfoo.util.security.IdUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.hardware.HardwareAbstractionLayer;
|
||||
import oshi.hardware.NetworkIF;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
@@ -302,4 +304,19 @@ public abstract class OSUtils {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
public static SystemInfoVo os() {
|
||||
CentralProcessor processor = hardware.getProcessor();
|
||||
SystemInfoVo systemInfo = new SystemInfoVo();
|
||||
systemInfo.setHostname(NetUtils.getLocalhostStr());
|
||||
systemInfo.setCpuCoreNum(processor.getLogicalProcessorCount() + "");
|
||||
String cpuInfo = processor.toString();
|
||||
if (cpuInfo.indexOf("\n") > 0) {
|
||||
cpuInfo = cpuInfo.substring(0, cpuInfo.indexOf("\n"));
|
||||
}
|
||||
systemInfo.setCpuXh(cpuInfo);
|
||||
systemInfo.setVersion(os.toString());
|
||||
systemInfo.setVersionDetail(os.toString());
|
||||
|
||||
return systemInfo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user