mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-09-03 08:19:37 +00:00
Merge pull request #24 from yujuncai/main
增加操作系统信息获取的工具类,并增加mongodb,TTL 类型 List<Data>和Data[] 的判断
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
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;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* core的个数(即核数)
|
||||
*/
|
||||
private String cpuCoreNum;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* CPU型号信息
|
||||
*/
|
||||
private String cpuXh;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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 String getCpuCoreNum() {
|
||||
return cpuCoreNum;
|
||||
}
|
||||
|
||||
public void setCpuCoreNum(String cpuCoreNum) {
|
||||
this.cpuCoreNum = cpuCoreNum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getCpuXh() {
|
||||
return cpuXh;
|
||||
}
|
||||
|
||||
public void setCpuXh(String cpuXh) {
|
||||
this.cpuXh = cpuXh;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,7 +338,14 @@ public class OrmManager implements IOrmManager {
|
||||
"class java.util.Date")){
|
||||
throw new IllegalArgumentException(StringUtils.format("[{}]不是Date类型", field.getName()));
|
||||
}
|
||||
|
||||
if (!field.getGenericType().toString().equals(
|
||||
"java.util.List<java.util.Date>")){
|
||||
throw new IllegalArgumentException(StringUtils.format("[{}]不是List<Date>类型", field.getName()));
|
||||
}
|
||||
if (!field.getGenericType().toString().equals(
|
||||
"class [Ljava.util.Date;")){
|
||||
throw new IllegalArgumentException(StringUtils.format("[{}]不是Date[]类型", field.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
IndexDef indexDef = new IndexDef(field, indexAnnotation.ascending(), indexAnnotation.unique(),indexAnnotation.ttl(),indexAnnotation.expireAfterSeconds());
|
||||
|
||||
Reference in New Issue
Block a user