采集信息增加时间戳
This commit is contained in:
@@ -86,8 +86,10 @@ public class HeartScheduler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 发送心跳包
|
// 发送心跳包
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
object.put("strength","31");
|
object.put("strength","31");
|
||||||
|
object.put("timestamp",timestamp);
|
||||||
String clientId = AgentUtil.getMotherboardUUID();
|
String clientId = AgentUtil.getMotherboardUUID();
|
||||||
Message message = Message.builder().clientId(clientId).dataType("HEARTBEAT").data(object.toString()).build();
|
Message message = Message.builder().clientId(clientId).dataType("HEARTBEAT").data(object.toString()).build();
|
||||||
// 将对象转为 JSON 字符串 标识
|
// 将对象转为 JSON 字符串 标识
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ public class CpuServiceImpl implements CpuService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CpuVO query() {
|
public CpuVO query() {
|
||||||
CpuVO cpuVO = CpuVO.builder().build();
|
// 获取当前时间戳(毫秒级)
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
|
CpuVO cpuVO = CpuVO.builder().timestamp(timestamp).build();
|
||||||
try {
|
try {
|
||||||
SystemInfo si = new SystemInfo();
|
SystemInfo si = new SystemInfo();
|
||||||
HardwareAbstractionLayer hal = si.getHardware();
|
HardwareAbstractionLayer hal = si.getHardware();
|
||||||
@@ -123,6 +125,9 @@ public class CpuServiceImpl implements CpuService {
|
|||||||
// duration.toHours() % 24,
|
// duration.toHours() % 24,
|
||||||
// duration.toMinutes() % 60,
|
// duration.toMinutes() % 60,
|
||||||
// duration.getSeconds() % 60);
|
// duration.getSeconds() % 60);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return cpuVO;
|
return cpuVO;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ public class DiskServiceImpl implements DiskService {
|
|||||||
List<DiskVO> tempList = new ArrayList<>();
|
List<DiskVO> tempList = new ArrayList<>();
|
||||||
List<DiskVO> resultList = new ArrayList<>();
|
List<DiskVO> resultList = new ArrayList<>();
|
||||||
SystemInfo si = new SystemInfo();
|
SystemInfo si = new SystemInfo();
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
System.out.println("=========================================================");
|
System.out.println("=========================================================");
|
||||||
// 获取磁盘IO信息
|
// 获取磁盘IO信息
|
||||||
System.out.println("\n=== 磁盘IO信息 ===");
|
System.out.println("\n=== 磁盘IO信息 ===");
|
||||||
for (HWDiskStore disk : si.getHardware().getDiskStores()) {
|
for (HWDiskStore disk : si.getHardware().getDiskStores()) {
|
||||||
DiskVO diskVO = DiskVO.builder().build();
|
DiskVO diskVO = DiskVO.builder().timestamp(timestamp).build();
|
||||||
diskVO.setName(disk.getName());//磁盘名称
|
diskVO.setName(disk.getName());//磁盘名称
|
||||||
diskVO.setSerial(disk.getSerial());//序列号
|
diskVO.setSerial(disk.getSerial());//序列号
|
||||||
diskVO.setTotal(disk.getSize());//磁盘大小
|
diskVO.setTotal(disk.getSize());//磁盘大小
|
||||||
@@ -94,6 +94,7 @@ public class DiskServiceImpl implements DiskService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<PointVO> queryPointList() {
|
public List<PointVO> queryPointList() {
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
List<PointVO> list = new ArrayList<>();
|
List<PointVO> list = new ArrayList<>();
|
||||||
SystemInfo si = new SystemInfo();
|
SystemInfo si = new SystemInfo();
|
||||||
// 获取文件系统信息
|
// 获取文件系统信息
|
||||||
@@ -106,7 +107,7 @@ public class DiskServiceImpl implements DiskService {
|
|||||||
double usagePercentage = totalSpace > 0 ?
|
double usagePercentage = totalSpace > 0 ?
|
||||||
(double) (totalSpace - freeSpace) / totalSpace * 100 : 0;
|
(double) (totalSpace - freeSpace) / totalSpace * 100 : 0;
|
||||||
|
|
||||||
PointVO pointVO = PointVO.builder().build();
|
PointVO pointVO = PointVO.builder().timestamp(timestamp).build();
|
||||||
pointVO.setMount(fs.getMount());//挂载点
|
pointVO.setMount(fs.getMount());//挂载点
|
||||||
pointVO.setVfsType(fs.getType());//文件系统类型
|
pointVO.setVfsType(fs.getType());//文件系统类型
|
||||||
pointVO.setVfsTotal(totalSpace);//总空间
|
pointVO.setVfsTotal(totalSpace);//总空间
|
||||||
|
|||||||
+2
-1
@@ -47,8 +47,9 @@ public class DockerServiceImpl implements DockerService {
|
|||||||
// 打印容器信息
|
// 打印容器信息
|
||||||
System.out.println("运行中的Docker容器:");
|
System.out.println("运行中的Docker容器:");
|
||||||
System.out.println("容器ID\t\t镜像\t\t状态\t\t名称");
|
System.out.println("容器ID\t\t镜像\t\t状态\t\t名称");
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
for (Container container : containers) {
|
for (Container container : containers) {
|
||||||
DockerVO dockerVO = DockerVO.builder().build();
|
DockerVO dockerVO = DockerVO.builder().timestamp(timestamp).build();
|
||||||
String id = container.getId().substring(0, 12); // 只显示短ID
|
String id = container.getId().substring(0, 12); // 只显示短ID
|
||||||
String image = container.getImage().length() > 15 ?
|
String image = container.getImage().length() > 15 ?
|
||||||
container.getImage().substring(0, 15) + "..." : container.getImage();
|
container.getImage().substring(0, 15) + "..." : container.getImage();
|
||||||
|
|||||||
+2
-1
@@ -14,7 +14,8 @@ import java.util.Map;
|
|||||||
public class MemoryServiceImpl implements MemoryService {
|
public class MemoryServiceImpl implements MemoryService {
|
||||||
@Override
|
@Override
|
||||||
public MemoryVO query() {
|
public MemoryVO query() {
|
||||||
MemoryVO memoryVO = MemoryVO.builder().build();
|
long timestamp = System.currentTimeMillis();
|
||||||
|
MemoryVO memoryVO = MemoryVO.builder().timestamp(timestamp).build();
|
||||||
try {
|
try {
|
||||||
Map<String, Long> memInfo = parseMemInfo();
|
Map<String, Long> memInfo = parseMemInfo();
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
public class NetServiceImpl implements NetService {
|
public class NetServiceImpl implements NetService {
|
||||||
@Override
|
@Override
|
||||||
public List<NetVO> query() {
|
public List<NetVO> query() {
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
List<NetVO> list = new ArrayList<>();
|
List<NetVO> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
SystemInfo si = new SystemInfo();
|
SystemInfo si = new SystemInfo();
|
||||||
@@ -75,6 +76,7 @@ public class NetServiceImpl implements NetService {
|
|||||||
netVO.setOutDropped(net.getCollisions());//出站丢包
|
netVO.setOutDropped(net.getCollisions());//出站丢包
|
||||||
netVO.setInSpeed(bytesRecv);//接收流量
|
netVO.setInSpeed(bytesRecv);//接收流量
|
||||||
netVO.setOutSpeed(bytesSent);//发送流量
|
netVO.setOutSpeed(bytesSent);//发送流量
|
||||||
|
netVO.setTimestamp(timestamp);
|
||||||
list.add(netVO);
|
list.add(netVO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -106,6 +106,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
System.out.printf("%-5s %-15s %-10s %-15s %-8s %-12s %-12s%n",
|
System.out.printf("%-5s %-15s %-10s %-15s %-8s %-12s %-12s%n",
|
||||||
"Index", "Name", "Type", "Speed", "Status", "InBytes", "OutBytes");
|
"Index", "Name", "Type", "Speed", "Status", "InBytes", "OutBytes");
|
||||||
List<SwitchBoardVO> list = new ArrayList<>();
|
List<SwitchBoardVO> list = new ArrayList<>();
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
for (int i = 1; i <= ifNumber; i++) {
|
for (int i = 1; i <= ifNumber; i++) {
|
||||||
pdu = new PDU();
|
pdu = new PDU();
|
||||||
for (String baseOID : ifOIDs) {
|
for (String baseOID : ifOIDs) {
|
||||||
@@ -128,6 +129,7 @@ public class SwitchBoardServiceImpl implements SwitchBoardService {
|
|||||||
.status(status)
|
.status(status)
|
||||||
.inBytes(inBytes)
|
.inBytes(inBytes)
|
||||||
.outBytes(outBytes)
|
.outBytes(outBytes)
|
||||||
|
.timestamp(timestamp)
|
||||||
.build();
|
.build();
|
||||||
list.add(boardVO);
|
list.add(boardVO);
|
||||||
System.out.printf("%-5d %-15s %-10s %-15s %-8s %-12d %-12d%n",
|
System.out.printf("%-5d %-15s %-10s %-15s %-8s %-12d %-12d%n",
|
||||||
|
|||||||
+2
-1
@@ -18,7 +18,8 @@ import java.time.format.DateTimeFormatter;
|
|||||||
public class SystemServiceImpl implements SystemService {
|
public class SystemServiceImpl implements SystemService {
|
||||||
@Override
|
@Override
|
||||||
public SystemVO query() {
|
public SystemVO query() {
|
||||||
SystemVO systemVO = SystemVO.builder().build();
|
long timestamp = System.currentTimeMillis();
|
||||||
|
SystemVO systemVO = SystemVO.builder().timestamp(timestamp).build();
|
||||||
try {
|
try {
|
||||||
SystemInfo si = new SystemInfo();
|
SystemInfo si = new SystemInfo();
|
||||||
HardwareAbstractionLayer hal = si.getHardware();
|
HardwareAbstractionLayer hal = si.getHardware();
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ public class CpuVO implements Serializable {
|
|||||||
@Schema(description = "CPU用户进程所花费的时间")
|
@Schema(description = "CPU用户进程所花费的时间")
|
||||||
private long user;
|
private long user;
|
||||||
|
|
||||||
|
@Schema(description = "时间戳")
|
||||||
|
private long timestamp;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,5 +43,8 @@ public class DiskVO implements Serializable {
|
|||||||
@Schema(description = "磁盘读取字节")
|
@Schema(description = "磁盘读取字节")
|
||||||
private long readBytes;
|
private long readBytes;
|
||||||
|
|
||||||
|
@Schema(description = "时间戳")
|
||||||
|
private long timestamp;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,5 +37,8 @@ public class DockerVO implements Serializable {
|
|||||||
@Schema(description = "容器网络发送速率")
|
@Schema(description = "容器网络发送速率")
|
||||||
private String netOutSpeed;
|
private String netOutSpeed;
|
||||||
|
|
||||||
|
@Schema(description = "时间戳")
|
||||||
|
private long timestamp;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,4 +34,7 @@ public class MemoryVO implements Serializable {
|
|||||||
@Schema(description = "总内存")
|
@Schema(description = "总内存")
|
||||||
private long total;
|
private long total;
|
||||||
|
|
||||||
|
@Schema(description = "时间戳")
|
||||||
|
private long timestamp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,4 +46,7 @@ public class NetVO implements Serializable {
|
|||||||
// @Schema(description = "接收速度")
|
// @Schema(description = "接收速度")
|
||||||
// private String speed;
|
// private String speed;
|
||||||
|
|
||||||
|
@Schema(description = "时间戳")
|
||||||
|
private long timestamp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,4 +30,7 @@ public class PointVO implements Serializable {
|
|||||||
|
|
||||||
@Schema(description = "空间利用率")
|
@Schema(description = "空间利用率")
|
||||||
private double vfsUtil;
|
private double vfsUtil;
|
||||||
|
|
||||||
|
@Schema(description = "时间戳")
|
||||||
|
private long timestamp;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,5 +31,8 @@ public class SwitchBoardVO implements Serializable {
|
|||||||
@Schema(description = "发送流量")
|
@Schema(description = "发送流量")
|
||||||
private long outBytes;
|
private long outBytes;
|
||||||
|
|
||||||
|
@Schema(description = "时间戳")
|
||||||
|
private long timestamp;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ public class SystemVO implements Serializable {
|
|||||||
|
|
||||||
private String uuid;
|
private String uuid;
|
||||||
|
|
||||||
// @Schema(description = "时间戳")
|
@Schema(description = "时间戳")
|
||||||
// private long timeStamp;
|
private long timestamp;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,8 +60,10 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<Message> {
|
|||||||
IdleStateEvent event = (IdleStateEvent) evt;
|
IdleStateEvent event = (IdleStateEvent) evt;
|
||||||
if (event.state() == IdleState.WRITER_IDLE) {
|
if (event.state() == IdleState.WRITER_IDLE) {
|
||||||
// 发送心跳包
|
// 发送心跳包
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
object.put("strength","31");
|
object.put("strength","31");
|
||||||
|
object.put("timestamp",timestamp);
|
||||||
String clientId = AgentUtil.getMotherboardUUID();
|
String clientId = AgentUtil.getMotherboardUUID();
|
||||||
Message message = Message.builder().clientId(clientId).dataType("HEARTBEAT").data(object.toString()).build();
|
Message message = Message.builder().clientId(clientId).dataType("HEARTBEAT").data(object.toString()).build();
|
||||||
// 将对象转为 JSON 字符串
|
// 将对象转为 JSON 字符串
|
||||||
@@ -86,9 +88,11 @@ public class NettyClientHandler extends SimpleChannelInboundHandler<Message> {
|
|||||||
retryCount = 0; // 连接成功时重置重试次数
|
retryCount = 0; // 连接成功时重置重试次数
|
||||||
|
|
||||||
// 连接建立后可以发送登录认证消息
|
// 连接建立后可以发送登录认证消息
|
||||||
|
long timestamp = System.currentTimeMillis();
|
||||||
String clientId = AgentUtil.getMotherboardUUID();
|
String clientId = AgentUtil.getMotherboardUUID();
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
object.put("uuid",clientId);
|
object.put("uuid",clientId);
|
||||||
|
object.put("timestamp",timestamp);
|
||||||
Message message = Message.builder().clientId(clientId).dataType("LOGIN").data(object.toString()).build();
|
Message message = Message.builder().clientId(clientId).dataType("LOGIN").data(object.toString()).build();
|
||||||
// 将对象转为 JSON 字符串
|
// 将对象转为 JSON 字符串
|
||||||
String json = "agent-tcp:"+JSON.toJSONString(message)+"@tong-ran";
|
String json = "agent-tcp:"+JSON.toJSONString(message)+"@tong-ran";
|
||||||
|
|||||||
Reference in New Issue
Block a user