[ Project ] 适配前端部分代码

This commit is contained in:
zeaslity
2023-08-02 14:30:01 +08:00
parent 98467f9590
commit 8e2eacfa47
22 changed files with 596 additions and 142 deletions

View File

@@ -0,0 +1,20 @@
package io.wdd.rpc.beans.request;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("查询Agent运行状态的请求实体")
public class MetricQueryEntity {
double metricStartTimeStamp;
double metricEndTimeStamp;
String agentTopicName;
}

View File

@@ -4,14 +4,14 @@ package io.wdd.rpc.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.wdd.common.response.R;
import io.wdd.rpc.beans.request.MetricQueryEntity;
import io.wdd.rpc.scheduler.service.status.AgentAliveStatusMonitorService;
import io.wdd.rpc.status.beans.AgentStatus;
import io.wdd.rpc.status.service.SyncStatusService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -55,7 +55,6 @@ public class StatusController {
@PostMapping("/agent/all/string")
public R<String> GetAllAgentString() {
String data = ALL_AGENT_TOPIC_NAME_LIST.toString();
data.replace("[",
"");
@@ -86,4 +85,14 @@ public class StatusController {
}
@ApiOperation("[ Agent-Metric ] 获取Agent的Metric信息")
@PostMapping("/agent/metric")
public R<ArrayList<AgentStatus>> QueryMetricStatus(
@RequestBody MetricQueryEntity metricQueryEntity
) {
return R.ok(syncStatusService.QueryMetricStatus(metricQueryEntity));
}
}

View File

@@ -1,15 +1,19 @@
package io.wdd.rpc.scheduler.service.status;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.wdd.common.utils.TimeUtils;
import io.wdd.rpc.status.beans.AgentStatus;
import io.wdd.rpc.status.service.SyncStatusService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.Map;
import static io.wdd.common.utils.OctopusObjectMapperConfig.OctopusObjectMapper;
import static io.wdd.rpc.status.CommonAndStatusCache.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
/**
@@ -23,6 +27,9 @@ public class AgentMetricStatusCollectService {
@Resource
SyncStatusService syncStatusService;
@Resource
RedisTemplate redisTemplate;
/**
* 收集所有健康主机的运行数据
*/
@@ -40,12 +47,42 @@ public class AgentMetricStatusCollectService {
10
);
// todo 需要进行存储或者咋滴
// 2023年7月14日 使用redis存储状态数据
log.info(
"[Agent Metric] - 所有主机的状态为 => {}",
agentMetricStatusMap
);
agentMetricStatusMap
.entrySet()
.stream()
.forEach(
entry -> {
try {
String agentMetricString = OctopusObjectMapper.writeValueAsString(entry.getValue());
double currentTime = TimeUtils.utcTimeStampOfDouble();
redisTemplate
.opsForZSet()
.add(
entry.getKey() + "-Metric",
agentMetricString,
currentTime
);
// todo 处理长度缓存
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
);
}

View File

@@ -119,12 +119,15 @@ public class CommonAndStatusCache {
ALL_AGENT_TOPIC_NAME_LIST.addAll(collect);
ALL_AGENT_TOPIC_NAME_SET.addAll(collect);
String[] all_agent_topic_name_array = new String[ALL_AGENT_TOPIC_NAME_LIST.size()];
ALL_AGENT_TOPIC_NAME_LIST.toArray(all_agent_topic_name_array);
// 2023年7月10日 同步缓存至Redis中
redisTemplate
.opsForSet()
.add(
ALL_AGENT_TOPIC_NAME_REDIS_KEY,
ALL_AGENT_TOPIC_NAME_SET
all_agent_topic_name_array
);
}

View File

@@ -17,7 +17,7 @@ public class CPUStatus {
@JsonProperty("NumCores")
private Integer numCores;
@JsonProperty("CPUStatus")
@JsonProperty("CPUInfo")
private List<CPUInfoDTO> cPUInfo;
@JsonProperty("CPUPercent")
private Double cPUPercent;

View File

@@ -4,8 +4,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@NoArgsConstructor
@Data
public class DiskStatus {
@@ -14,19 +12,19 @@ public class DiskStatus {
private Long total;
@JsonProperty("Used")
private Long used;
@JsonProperty("LogicalDisk")
private List<LogicalDiskDTO> logicalDisk;
// @JsonProperty("LogicalDisk")
// private List<LogicalDiskDTO> logicalDisk;
@NoArgsConstructor
@Data
public static class LogicalDiskDTO {
@JsonProperty("device")
private String device;
@JsonProperty("mountpoint")
private String mountpoint;
@JsonProperty("fstype")
private String fstype;
@JsonProperty("opts")
private List<String> opts;
}
// @NoArgsConstructor
// @Data
// public static class LogicalDiskDTO {
// @JsonProperty("device")
// private String device;
// @JsonProperty("mountpoint")
// private String mountpoint;
// @JsonProperty("fstype")
// private String fstype;
// @JsonProperty("opts")
// private List<String> opts;
// }
}

View File

@@ -1,7 +1,9 @@
package io.wdd.rpc.status.service;
import io.wdd.rpc.beans.request.MetricQueryEntity;
import io.wdd.rpc.status.beans.AgentStatus;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -24,4 +26,15 @@ public interface SyncStatusService {
* @return
*/
Map<String, AgentStatus> SyncCollectAgentMetricStatus(List<String> agentTopicNameList, int collectMetricWaitMaxTime);
/* Metric 调用的后端接口 */
/**
* 根据前端的请求实体查询相应的Metric信息
*
* @return
*/
ArrayList<AgentStatus> QueryMetricStatus(MetricQueryEntity metricQueryEntity);
}

View File

@@ -2,6 +2,7 @@ package io.wdd.rpc.status.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.wdd.common.utils.TimeUtils;
import io.wdd.rpc.beans.request.MetricQueryEntity;
import io.wdd.rpc.message.OctopusMessage;
import io.wdd.rpc.message.OctopusMessageType;
import io.wdd.rpc.message.handler.async.AsyncWaitOctopusMessageResultService;
@@ -9,10 +10,12 @@ import io.wdd.rpc.message.handler.async.OctopusMessageSynScReplayContend;
import io.wdd.rpc.message.sender.OMessageToAgentSender;
import io.wdd.rpc.status.beans.AgentStatus;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -35,6 +38,9 @@ public class SyncStatusServiceImpl implements SyncStatusService {
@Resource
AsyncWaitOctopusMessageResultService asyncWaitOctopusMessageResultService;
@Resource
RedisTemplate redisTemplate;
@Override
public Map<String, Boolean> SyncCollectAgentAliveStatus(List<String> agentTopicNameList, int aliveStatusWaitMaxTime) {
@@ -185,6 +191,52 @@ public class SyncStatusServiceImpl implements SyncStatusService {
return metricMap;
}
@Override
public ArrayList<AgentStatus> QueryMetricStatus(MetricQueryEntity metricQueryEntity) {
String queryRedisKey = metricQueryEntity.getAgentTopicName() + "-Metric";
if (!redisTemplate.hasKey(queryRedisKey)) {
log.error(
"[Metric] - 查询到没有此Agent {} 的Metric信息直接返回",
metricQueryEntity.getAgentTopicName()
);
}
double start = metricQueryEntity.getMetricStartTimeStamp();
double end = metricQueryEntity.getMetricEndTimeStamp();
ArrayList<AgentStatus> statusArrayList = new ArrayList<>();
redisTemplate
.opsForZSet()
.rangeByScore(
queryRedisKey,
start,
end
)
.stream()
.forEachOrdered(
metricString -> {
try {
AgentStatus agentStatus = OctopusObjectMapper.readValue(
(String) metricString,
AgentStatus.class
);
statusArrayList.add(agentStatus);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
);
return statusArrayList;
}
/**
* 2023年7月10日 通用的底层构造方法 Status类型的Octopus Message