设置采集间隔初始化默认值5分钟
增加指令更新采集间隔
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
package com.tongran.agentserver.server.netty.annotation;
|
||||||
|
|
||||||
|
import com.tongran.agentserver.core.enums.MsgEnum;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 指明类为Agent消息
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Documented
|
||||||
|
@Target({ElementType.TYPE})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface AgentDispatcher {
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
enum VersionEnum {
|
||||||
|
V1("2025");
|
||||||
|
public final String value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息ID
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
MsgEnum msgId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息版本 默认版本2025
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
VersionEnum version() default VersionEnum.V1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String desc() default "";
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.tongran.agentserver.server.netty.basics;
|
||||||
|
|
||||||
|
|
||||||
|
import com.tongran.agentserver.server.netty.model.UpMsgResponse;
|
||||||
|
|
||||||
|
public interface AgentHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理终端传入的消息, 然后进行返回
|
||||||
|
*
|
||||||
|
* @return 需要发送给终端的消息
|
||||||
|
*/
|
||||||
|
|
||||||
|
default UpMsgResponse upHandle(String data,String clientId) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
package com.tongran.agentserver.server.netty.enpoint;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.tongran.agentserver.core.enums.MsgEnum;
|
||||||
|
import com.tongran.agentserver.scheduler.*;
|
||||||
|
import com.tongran.agentserver.server.netty.annotation.AgentDispatcher;
|
||||||
|
import com.tongran.agentserver.server.netty.basics.AgentHandler;
|
||||||
|
import com.tongran.agentserver.server.netty.model.UpMsgResponse;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class AgentEndpoint {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CpuScheduler cpuScheduler;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DiskScheduler diskScheduler;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private DockerScheduler dockerScheduler;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MemoryScheduler memoryScheduler;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private NetScheduler netScheduler;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private PointScheduler pointScheduler;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SwitchBoardScheduler switchBoardScheduler;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysScheduler sysScheduler;
|
||||||
|
|
||||||
|
|
||||||
|
@AgentDispatcher(msgId = MsgEnum.更新CPU采集间隔)
|
||||||
|
public class TimeCpuHandler implements AgentHandler {
|
||||||
|
@Override
|
||||||
|
public UpMsgResponse upHandle(String data, String clientId) {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
|
long intervalMillis = jsonObject.getLong("intervalMillis");
|
||||||
|
cpuScheduler.updateInterval(intervalMillis);
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("clientId",clientId);
|
||||||
|
json.put("resCode",1);
|
||||||
|
return UpMsgResponse.builder().dataType(MsgEnum.更新CPU采集间隔应答.getValue()).content(json.toString()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AgentDispatcher(msgId = MsgEnum.更新容器采集间隔)
|
||||||
|
public class TimeDockerHandler implements AgentHandler {
|
||||||
|
@Override
|
||||||
|
public UpMsgResponse upHandle(String data, String clientId) {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
|
long intervalMillis = jsonObject.getLong("intervalMillis");
|
||||||
|
cpuScheduler.updateInterval(intervalMillis);
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("clientId",clientId);
|
||||||
|
json.put("resCode",1);
|
||||||
|
return UpMsgResponse.builder().dataType(MsgEnum.更新容器采集间隔应答.getValue()).content(json.toString()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AgentDispatcher(msgId = MsgEnum.更新CPU采集间隔)
|
||||||
|
public class CpuHandler implements AgentHandler {
|
||||||
|
@Override
|
||||||
|
public UpMsgResponse upHandle(String data, String clientId) {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
|
long intervalMillis = jsonObject.getLong("intervalMillis");
|
||||||
|
dockerScheduler.updateInterval(intervalMillis);
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("clientId",clientId);
|
||||||
|
json.put("resCode",1);
|
||||||
|
return UpMsgResponse.builder().dataType(MsgEnum.更新CPU采集间隔应答.getValue()).content(json.toString()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AgentDispatcher(msgId = MsgEnum.更新网卡采集间隔)
|
||||||
|
public class TimeNetHandler implements AgentHandler {
|
||||||
|
@Override
|
||||||
|
public UpMsgResponse upHandle(String data, String clientId) {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
|
long intervalMillis = jsonObject.getLong("intervalMillis");
|
||||||
|
netScheduler.updateInterval(intervalMillis);
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("clientId",clientId);
|
||||||
|
json.put("resCode",1);
|
||||||
|
return UpMsgResponse.builder().dataType(MsgEnum.更新网卡采集间隔应答.getValue()).content(json.toString()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AgentDispatcher(msgId = MsgEnum.更新交换机采集间隔)
|
||||||
|
public class TimeSwitchHandler implements AgentHandler {
|
||||||
|
@Override
|
||||||
|
public UpMsgResponse upHandle(String data, String clientId) {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
|
long intervalMillis = jsonObject.getLong("intervalMillis");
|
||||||
|
switchBoardScheduler.updateInterval(intervalMillis);
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("clientId",clientId);
|
||||||
|
json.put("resCode",1);
|
||||||
|
return UpMsgResponse.builder().dataType(MsgEnum.更新交换机采集间隔应答.getValue()).content(json.toString()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AgentDispatcher(msgId = MsgEnum.更新磁盘采集间隔)
|
||||||
|
public class TimeDiskHandler implements AgentHandler {
|
||||||
|
@Override
|
||||||
|
public UpMsgResponse upHandle(String data, String clientId) {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
|
long intervalMillis = jsonObject.getLong("intervalMillis");
|
||||||
|
diskScheduler.updateInterval(intervalMillis);
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("clientId",clientId);
|
||||||
|
json.put("resCode",1);
|
||||||
|
return UpMsgResponse.builder().dataType(MsgEnum.更新磁盘采集间隔应答.getValue()).content(json.toString()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AgentDispatcher(msgId = MsgEnum.更新挂载采集间隔)
|
||||||
|
public class TimePointHandler implements AgentHandler {
|
||||||
|
@Override
|
||||||
|
public UpMsgResponse upHandle(String data, String clientId) {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
|
long intervalMillis = jsonObject.getLong("intervalMillis");
|
||||||
|
pointScheduler.updateInterval(intervalMillis);
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("clientId",clientId);
|
||||||
|
json.put("resCode",1);
|
||||||
|
return UpMsgResponse.builder().dataType(MsgEnum.更新挂载采集间隔应答.getValue()).content(json.toString()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AgentDispatcher(msgId = MsgEnum.更新内存采集间隔)
|
||||||
|
public class TimeMemoryHandler implements AgentHandler {
|
||||||
|
@Override
|
||||||
|
public UpMsgResponse upHandle(String data, String clientId) {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
|
long intervalMillis = jsonObject.getLong("intervalMillis");
|
||||||
|
memoryScheduler.updateInterval(intervalMillis);
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("clientId",clientId);
|
||||||
|
json.put("resCode",1);
|
||||||
|
return UpMsgResponse.builder().dataType(MsgEnum.更新内存采集间隔应答.getValue()).content(json.toString()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@AgentDispatcher(msgId = MsgEnum.更新系统采集间隔)
|
||||||
|
public class TimeSysHandler implements AgentHandler {
|
||||||
|
@Override
|
||||||
|
public UpMsgResponse upHandle(String data, String clientId) {
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
|
long intervalMillis = jsonObject.getLong("intervalMillis");
|
||||||
|
sysScheduler.updateInterval(intervalMillis);
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("clientId",clientId);
|
||||||
|
json.put("resCode",1);
|
||||||
|
return UpMsgResponse.builder().dataType(MsgEnum.更新系统采集间隔应答.getValue()).content(json.toString()).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.tongran.agentserver.server.netty.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UpMsgResponse {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* type
|
||||||
|
*/
|
||||||
|
private String dataType;
|
||||||
|
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user