[ Server ] [ Status ] - refresh status part
This commit is contained in:
@@ -35,13 +35,18 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>lettuce-core</artifactId>
|
||||
<groupId>io.lettuce</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!--<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||
<version>3.13.6</version>
|
||||
</dependency>-->
|
||||
<!-- lettuce pool 缓存连接池-->
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
</dependency>
|
||||
<!-- redis pool 缓存连接池-->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
|
||||
46
server/src/main/java/io/wdd/common/config/JedisConfig.java
Normal file
46
server/src/main/java/io/wdd/common/config/JedisConfig.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package io.wdd.common.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class JedisConfig {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(JedisConfig.class);
|
||||
|
||||
@Value("${spring.redis.host}")
|
||||
private String host;
|
||||
@Value("${spring.redis.port}")
|
||||
private int port;
|
||||
@Value("${spring.redis.password}")
|
||||
private String password;
|
||||
@Value("${spring.redis.timeout}")
|
||||
private int timeout;
|
||||
@Value("${spring.redis.jedis.pool.max-idle}")
|
||||
private int maxIdle;
|
||||
@Value("${spring.redis.jedis.pool.max-active}")
|
||||
private int maxActive;
|
||||
@Value("${spring.redis.jedis.pool.min-idle}")
|
||||
private int minIdle;
|
||||
|
||||
@Bean
|
||||
public JedisPool jedisPool() {
|
||||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||
jedisPoolConfig.setMaxIdle(maxIdle);
|
||||
jedisPoolConfig.setMaxTotal(maxActive);
|
||||
jedisPoolConfig.setMinIdle(minIdle);
|
||||
|
||||
JedisPool jedisPool = new JedisPool(jedisPoolConfig, host, port, timeout, null);
|
||||
|
||||
logger.info("JedisPoll连接成功:" + host + "\t" + port);
|
||||
|
||||
return jedisPool;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class TimeUtils {
|
||||
|
||||
if (ObjectUtils.isEmpty(UNIFORM_TIME)) {
|
||||
UNIFORM_TIME = currentTime();
|
||||
return currentFormatTimeString();
|
||||
return forwardRoundingTimeString();
|
||||
}
|
||||
|
||||
// 旧的时间和新时间之家误差小于5秒,那么使用同一个时间
|
||||
@@ -105,7 +105,25 @@ public class TimeUtils {
|
||||
}
|
||||
|
||||
return localDateTimeFormatString(UNIFORM_TIME);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2023-12-22-11-37-41 should return 2023-12-22-11-37-40
|
||||
* 2023-12-22-11-37-47 should return 2023-12-22-11-37-45
|
||||
*
|
||||
* @return forward rounding time
|
||||
*/
|
||||
private static String forwardRoundingTimeString() {
|
||||
|
||||
LocalDateTime now = currentTime();
|
||||
|
||||
int second = now.getSecond();
|
||||
while (second % 5 != 0) {
|
||||
now = now.minusSeconds(1);
|
||||
second = second - 1;
|
||||
}
|
||||
|
||||
return localDateTimeFormatString(now);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -122,7 +140,6 @@ public class TimeUtils {
|
||||
.format(ofPattern);
|
||||
|
||||
return LocalDateTime.parse(format, ofPattern);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -131,8 +148,7 @@ public class TimeUtils {
|
||||
*/
|
||||
public static String currentFormatTimeString() {
|
||||
|
||||
return currentFormatTime()
|
||||
.format(DateTimeFormatter.ofPattern(FULL_SPLIT_TIME_FORMAT));
|
||||
return localDateTimeFormatString(currentTime());
|
||||
}
|
||||
|
||||
public static LocalDateTime cvFromDate(Date date) {
|
||||
@@ -156,23 +172,10 @@ public class TimeUtils {
|
||||
.format(DateTimeFormatter.ofPattern(COMMON_TIME_FORMAT));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return UTC+8 [ yyyy-MM-dd-HH-mm-ss ] Time String
|
||||
*/
|
||||
public static String currentTimeStringFullSplit() {
|
||||
|
||||
return LocalDateTime
|
||||
.now(SYSTEM_TIME_ZONE_ID)
|
||||
.format(DateTimeFormatter.ofPattern(FULL_SPLIT_TIME_FORMAT));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 输出格式为 COMMON_TIME_FORMAT "yyyy-MM-dd HH:mm:ss"
|
||||
*
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
public static String localDateTimeString(LocalDateTime time) {
|
||||
return time.format(DateTimeFormatter.ofPattern(COMMON_TIME_FORMAT));
|
||||
|
||||
@@ -100,17 +100,17 @@ public class AppFuncScheduler {
|
||||
);
|
||||
|
||||
List<AppFunctionEnum> appFunctionEnumList = List.of(
|
||||
// AppFunctionEnum.DEPLOY_CHRONY_SERVER,
|
||||
// AppFunctionEnum.DEPLOY_RKE
|
||||
AppFunctionEnum.DEPLOY_K8S_DASHBOARD,
|
||||
AppFunctionEnum.DEPLOY_NFS,
|
||||
AppFunctionEnum.DEPLOY_TEST_NFS,
|
||||
AppFunctionEnum.DEPLOY_K8S_NAMESPACE,
|
||||
AppFunctionEnum.DEPLOY_K8S_PVC,
|
||||
AppFunctionEnum.DEPLOY_K8S_MYSQL,
|
||||
AppFunctionEnum.DEPLOY_K8S_REDIS,
|
||||
AppFunctionEnum.DEPLOY_K8S_MIDDLEWARES,
|
||||
AppFunctionEnum.DEPLOY_INGRESS
|
||||
AppFunctionEnum.DEPLOY_CHRONY_SERVER,
|
||||
AppFunctionEnum.DEPLOY_RKE
|
||||
// AppFunctionEnum.DEPLOY_K8S_DASHBOARD,
|
||||
// AppFunctionEnum.DEPLOY_NFS,
|
||||
// AppFunctionEnum.DEPLOY_TEST_NFS,
|
||||
// AppFunctionEnum.DEPLOY_K8S_NAMESPACE,
|
||||
// AppFunctionEnum.DEPLOY_K8S_PVC,
|
||||
// AppFunctionEnum.DEPLOY_K8S_MYSQL,
|
||||
// AppFunctionEnum.DEPLOY_K8S_REDIS,
|
||||
// AppFunctionEnum.DEPLOY_K8S_MIDDLEWARES,
|
||||
// AppFunctionEnum.DEPLOY_INGRESS
|
||||
// AppFunctionEnum.DEPLOY_FRONTEND
|
||||
// AppFunctionEnum.DEPLOY_BACKEND
|
||||
// AppFunctionEnum.DEPLOY_K8S_SRS
|
||||
|
||||
@@ -6,7 +6,7 @@ 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.beans.AgentMetric;
|
||||
import io.wdd.rpc.status.service.SyncStatusService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -17,7 +17,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.wdd.rpc.status.CommonAndStatusCache.*;
|
||||
import static io.wdd.rpc.status.AllAgentStatusCache.*;
|
||||
|
||||
|
||||
//@RestController
|
||||
@@ -89,7 +89,7 @@ public class StatusController {
|
||||
|
||||
@ApiOperation("[ Agent-Metric ] 获取Agent的Metric信息")
|
||||
@PostMapping("/agent/metric")
|
||||
public R<ArrayList<AgentStatus>> QueryMetricStatus(
|
||||
public R<ArrayList<AgentMetric>> QueryMetricStatus(
|
||||
@RequestBody MetricQueryEntity metricQueryEntity
|
||||
) {
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.wdd.rpc.message.handler.OMessageHandler.*;
|
||||
import static io.wdd.rpc.status.CommonAndStatusCache.ALL_AGENT_TOPIC_NAME_SET;
|
||||
import static io.wdd.rpc.status.AllAgentStatusCache.ALL_AGENT_TOPIC_NAME_SET;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -173,6 +173,9 @@ public class ExecutionServiceImpl implements ExecutionService {
|
||||
|
||||
private boolean validateCommandInfo(String agentTopicName) {
|
||||
|
||||
// todo remove
|
||||
ALL_AGENT_TOPIC_NAME_SET.add("Chengdu-amd64-99-3b1609");
|
||||
|
||||
// 检查agentTopicName是否存在
|
||||
if (!ALL_AGENT_TOPIC_NAME_SET.contains(agentTopicName)) {
|
||||
log.error(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.wdd.rpc.scheduler.service.status;
|
||||
|
||||
import io.wdd.common.utils.TimeUtils;
|
||||
import io.wdd.rpc.status.CommonAndStatusCache;
|
||||
import io.wdd.rpc.status.AllAgentStatusCache;
|
||||
import io.wdd.rpc.status.service.SyncStatusService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
@@ -13,7 +13,7 @@ import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.wdd.rpc.status.CommonAndStatusCache.*;
|
||||
import static io.wdd.rpc.status.AllAgentStatusCache.*;
|
||||
import static io.wdd.rpc.status.OctopusStatusMessage.ALL_AGENT_STATUS_REDIS_KEY;
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ public class AgentAliveStatusMonitorService {
|
||||
RedisTemplate redisTemplate;
|
||||
|
||||
@Resource
|
||||
CommonAndStatusCache commonAndStatusCache;
|
||||
AllAgentStatusCache allAgentStatusCache;
|
||||
|
||||
@Resource
|
||||
SyncStatusService syncStatusService;
|
||||
@@ -42,7 +42,7 @@ public class AgentAliveStatusMonitorService {
|
||||
public void collectAllAgentAliveStatus() {
|
||||
|
||||
// 1. 获取所有注册的Agent 手动更新
|
||||
commonAndStatusCache.updateAllAgentTopicNameCache();
|
||||
allAgentStatusCache.commonUpdateAllAgentTopicNameCache();
|
||||
if (CollectionUtils.isEmpty(ALL_AGENT_TOPIC_NAME_LIST)) {
|
||||
log.warn("[Scheduler] No Agent Registered ! End Up Status Monitor !");
|
||||
return;
|
||||
@@ -53,7 +53,7 @@ public class AgentAliveStatusMonitorService {
|
||||
|
||||
// 2023年6月14日 2. 发送ping等待所有的Agent返回PONG, 然后进行redis的状态修改
|
||||
// 同步的方法, 超时等待所有主机的存活状态
|
||||
Map<String, Boolean> agentAliveStatusMap = syncStatusService.SyncCollectAgentAliveStatus(
|
||||
Map<String, Boolean> agentAliveStatusMap = syncStatusService.SyncCheckAgentIsAlive(
|
||||
ALL_AGENT_TOPIC_NAME_LIST,
|
||||
5
|
||||
);
|
||||
@@ -110,7 +110,7 @@ public class AgentAliveStatusMonitorService {
|
||||
String currentTimeString = TimeUtils.currentTimeString();
|
||||
|
||||
// 更新 二级缓存
|
||||
commonAndStatusCache.updateAgentStatusCache(agentAliveStatusMap);
|
||||
allAgentStatusCache.updateAgentStatusCache(agentAliveStatusMap);
|
||||
|
||||
// 更新 一级缓存
|
||||
// 这里仅仅是更新时间
|
||||
|
||||
@@ -3,7 +3,7 @@ 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.beans.AgentMetric;
|
||||
import io.wdd.rpc.status.service.SyncStatusService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
@@ -13,7 +13,7 @@ import javax.annotation.Resource;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.wdd.common.config.OctopusObjectMapperConfig.OctopusObjectMapper;
|
||||
import static io.wdd.rpc.status.CommonAndStatusCache.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
|
||||
import static io.wdd.rpc.status.AllAgentStatusCache.ALL_HEALTHY_AGENT_TOPIC_NAME_LIST;
|
||||
|
||||
/**
|
||||
* 定时任务 收集Agent的运行Metric的实际执行类
|
||||
@@ -41,7 +41,7 @@ public class AgentMetricStatusCollectService {
|
||||
}
|
||||
|
||||
// 调用核心的服务
|
||||
Map<String, AgentStatus> agentMetricStatusMap = syncStatusService.SyncCollectAgentMetricStatus(
|
||||
Map<String, AgentMetric> agentMetricStatusMap = syncStatusService.SyncCollectAgentMetricStatus(
|
||||
ALL_HEALTHY_AGENT_TOPIC_NAME_LIST,
|
||||
10
|
||||
);
|
||||
|
||||
@@ -6,8 +6,9 @@ import io.wdd.server.beans.po.ServerInfoPO;
|
||||
import io.wdd.server.coreService.CoreServerService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
@@ -27,7 +28,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class CommonAndStatusCache {
|
||||
public class AllAgentStatusCache {
|
||||
|
||||
/**
|
||||
* 存储所有的AgentTopicName的缓存
|
||||
@@ -58,27 +59,34 @@ public class CommonAndStatusCache {
|
||||
/**
|
||||
* 记录状态信息缓存的更新时间
|
||||
*/
|
||||
public static final String STATUS_UPDATE_TIME_KEY = "UPDATE_TIME";
|
||||
public static final String STATUS_UPDATE_TIME_KEY = "A-UPDATE_TIME";
|
||||
/**
|
||||
* 记录状态信息缓存的初始化时间
|
||||
*/
|
||||
public static final String STATUS_INIT_TIME_KEY = "INIT_TIME";
|
||||
public static final String STATUS_INIT_TIME_KEY = "A-INIT_TIME";
|
||||
/**
|
||||
* AgentTopicName 在Redis中緩存的Key
|
||||
*/
|
||||
private static final String ALL_AGENT_TOPIC_NAME_REDIS_KEY = "ALL_AGENT_TOPIC_NAME";
|
||||
private static final String ALL_AGENT_HEALTHY_MAP_REDIS_KEY = "ALL_AGENT_HEALTHY_MAP";
|
||||
|
||||
private static final String ALL_STATUS_AGENT_MAP_REDIS_KEY = "ALL_STATUS_AGENT_MAP";
|
||||
|
||||
private static final String ALL_AGENT_TOPIC_NAME_SET_REDIS_KEY = "ALL_AGENT_TOPIC_NAME";
|
||||
|
||||
@Resource
|
||||
CoreServerService coreServerService;
|
||||
|
||||
@Resource
|
||||
RedisTemplate redisTemplate;
|
||||
JedisPool jedisPool;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void InitToGenerateAllStatusCache() {
|
||||
|
||||
//所有Agent的TopicName ALL_AGENT_TOPIC_NAME_SET
|
||||
updateAllAgentTopicNameCache();
|
||||
commonUpdateAllAgentTopicNameCache();
|
||||
//
|
||||
initUpdateAllAgentStatusCache();
|
||||
|
||||
// Agent状态信息的两个Map
|
||||
// 初始化 默认创建全部失败的Map
|
||||
@@ -89,7 +97,65 @@ public class CommonAndStatusCache {
|
||||
topicName -> Boolean.FALSE
|
||||
));
|
||||
|
||||
updateAgentStatusCache(initAgentFalseStatusMap);
|
||||
// agent status cache
|
||||
// updateAgentStatusCache(initAgentFalseStatusMap);
|
||||
|
||||
}
|
||||
|
||||
private void initUpdateAllAgentStatusCache() {
|
||||
|
||||
if (CollectionUtils.isEmpty(ALL_AGENT_TOPIC_NAME_LIST)) {
|
||||
log.info("[Serer Boot Up] - no agent registered yet !");
|
||||
return;
|
||||
}
|
||||
|
||||
Jedis jedis = jedisPool.getResource();
|
||||
// delete from redis
|
||||
if (jedis.exists(ALL_AGENT_HEALTHY_MAP_REDIS_KEY)) {
|
||||
jedis.del(ALL_AGENT_HEALTHY_MAP_REDIS_KEY);
|
||||
}
|
||||
if (jedis.exists(ALL_STATUS_AGENT_MAP_REDIS_KEY)) {
|
||||
jedis.del(ALL_STATUS_AGENT_MAP_REDIS_KEY);
|
||||
}
|
||||
|
||||
// create ALL_AGENT_HEALTHY_MAP_REDIS_KEY
|
||||
Map<String, Boolean> initAgentFalseStatusMap = ALL_AGENT_TOPIC_NAME_LIST
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
topicName -> topicName,
|
||||
topicName -> Boolean.FALSE
|
||||
));
|
||||
Map<String, String> initAgentFalseRedisMap = ALL_AGENT_TOPIC_NAME_LIST
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
topicName -> topicName,
|
||||
topicName -> Boolean.FALSE.toString()
|
||||
));
|
||||
|
||||
// add time
|
||||
String currentFormatTimeString = TimeUtils.currentFormatTimeString();
|
||||
|
||||
initAgentFalseRedisMap.put(STATUS_UPDATE_TIME_KEY, currentFormatTimeString);
|
||||
initAgentFalseRedisMap.put(STATUS_INIT_TIME_KEY, currentFormatTimeString);
|
||||
if (jedis.hset(ALL_AGENT_HEALTHY_MAP_REDIS_KEY, initAgentFalseRedisMap) > 0) {
|
||||
|
||||
log.debug(" ALL_AGENT_HEALTHY_MAP_REDIS_KEY of {} has updated !", ALL_AGENT_HEALTHY_MAP_REDIS_KEY);
|
||||
ALL_AGENT_STATUS_MAP.clear();
|
||||
ALL_AGENT_STATUS_MAP.putAll(initAgentFalseStatusMap);
|
||||
}
|
||||
|
||||
// create ALL_STATUS_AGENT_MAP_REDIS_KEY
|
||||
Map<String, List<String>> statusAgentMapFromAgentStatusMap = buildStatusAgentMapFromAgentStatusMap(initAgentFalseStatusMap);
|
||||
|
||||
// convert
|
||||
statusAgentMapFromAgentStatusMap.entrySet().stream().collect(Collectors.toMap(
|
||||
entry -> entry.getKey(),
|
||||
entry -> String.join(",", entry.getValue())
|
||||
));
|
||||
// add time
|
||||
// statusAgentMapFromAgentStatusMap.put(STATUS_UPDATE_TIME_KEY, );
|
||||
// statusAgentMapFromAgentStatusMap.put(STATUS_UPDATE_TIME_KEY, currentFormatTimeString);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -98,7 +164,7 @@ public class CommonAndStatusCache {
|
||||
* <p>
|
||||
* 2023年7月10日 写入Redis中保存一份
|
||||
*/
|
||||
public void updateAllAgentTopicNameCache() {
|
||||
public void commonUpdateAllAgentTopicNameCache() {
|
||||
|
||||
//查询DB
|
||||
List<ServerInfoPO> allAgentInfo = coreServerService.serverGetAll();
|
||||
@@ -119,21 +185,22 @@ public class CommonAndStatusCache {
|
||||
ALL_AGENT_TOPIC_NAME_LIST.addAll(collect);
|
||||
ALL_AGENT_TOPIC_NAME_SET.addAll(collect);
|
||||
|
||||
Jedis jedis = jedisPool.getResource();
|
||||
|
||||
if (jedis.exists(ALL_AGENT_TOPIC_NAME_SET_REDIS_KEY)) {
|
||||
jedis.del(ALL_AGENT_TOPIC_NAME_SET_REDIS_KEY);
|
||||
}
|
||||
|
||||
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_array
|
||||
);
|
||||
|
||||
jedis.sadd(ALL_AGENT_TOPIC_NAME_SET_REDIS_KEY, all_agent_topic_name_array);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* COMMON-USAGE
|
||||
*
|
||||
* 根据传入的状态Map更新二级缓存的两个状态Map和健康主机的列表
|
||||
* ALL_AGENT_STATUS_MAP
|
||||
* STATUS_AGENT_LIST_MAP
|
||||
@@ -189,6 +256,11 @@ public class CommonAndStatusCache {
|
||||
STATUS_UPDATE_TIME_KEY,
|
||||
Collections.singletonList(timeString)
|
||||
);
|
||||
// 2023年12月22日
|
||||
ALL_AGENT_STATUS_MAP.put(
|
||||
STATUS_UPDATE_TIME_KEY,
|
||||
Boolean.TRUE
|
||||
);
|
||||
|
||||
// 缓存相应的存活Agent
|
||||
List<String> allHealthyAgentTopicNames = agentAliveStatusMap
|
||||
@@ -213,12 +285,59 @@ public class CommonAndStatusCache {
|
||||
ALL_AGENT_STATUS_MAP
|
||||
);
|
||||
|
||||
|
||||
// 2023年12月22日 add
|
||||
Jedis jedis = jedisPool.getResource();
|
||||
|
||||
if (jedis.exists(ALL_AGENT_HEALTHY_MAP_REDIS_KEY)) {
|
||||
// get the old cache
|
||||
//Map<String, String> all_agent_healthy_map_old = jedis.hgetAll(ALL_AGENT_HEALTHY_MAP_REDIS_KEY);
|
||||
// del the old
|
||||
jedis.del(ALL_AGENT_HEALTHY_MAP_REDIS_KEY);
|
||||
}
|
||||
|
||||
if (jedis.exists(ALL_STATUS_AGENT_MAP_REDIS_KEY)) {
|
||||
jedis.del(ALL_STATUS_AGENT_MAP_REDIS_KEY);
|
||||
}
|
||||
|
||||
// help gc
|
||||
agentAliveStatusMap = null;
|
||||
statusAgentListMap = null;
|
||||
allHealthyAgentTopicNames = null;
|
||||
}
|
||||
|
||||
private Map<String, List<String>> buildStatusAgentMapFromAgentStatusMap(Map<String, Boolean> agentStatusMap) {
|
||||
|
||||
// 2023-01-16 2023年12月22日
|
||||
// 更新 状态-Agent容器 内容为
|
||||
// HEALTHY -> ["agentTopicName-1", "agentTopicName-2"]
|
||||
// FAILED -> ["agentTopicName-1", "agentTopicName-2"]
|
||||
Map<String, List<String>> statusAgentListMap = agentStatusMap
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.groupingBy(
|
||||
Map.Entry::getValue
|
||||
)
|
||||
)
|
||||
.entrySet()
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
entry -> entry.getKey() ? "HEALTHY" : "FAILED",
|
||||
entry -> entry
|
||||
.getValue()
|
||||
.stream()
|
||||
.map(
|
||||
Map.Entry::getKey
|
||||
)
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
);
|
||||
|
||||
return statusAgentListMap;
|
||||
}
|
||||
|
||||
private String uniformHealthyStatus(String agentStatus) {
|
||||
switch (agentStatus) {
|
||||
case "0":
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.wdd.rpc.status.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class AgentMetric {
|
||||
|
||||
@JsonProperty("CPUMetric")
|
||||
private CPUMetric cpuMetric;
|
||||
|
||||
@JsonProperty("MemoryMetric")
|
||||
private MemoryMetric memoryMetric;
|
||||
|
||||
@JsonProperty("NetworkMetric")
|
||||
private List<NetworkMetric> networkMetricList;
|
||||
|
||||
@JsonProperty("DiskInfo")
|
||||
private List<DiskInfo> diskInfoList;
|
||||
|
||||
@JsonProperty("DockerMetric")
|
||||
private DockerMetric dockerMetric;
|
||||
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package io.wdd.rpc.status.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class AgentStatus {
|
||||
|
||||
@JsonProperty("CPUStatus")
|
||||
private CPUStatus cpuStatus;
|
||||
|
||||
@JsonProperty("MemoryStatus")
|
||||
private MemoryStatus memoryStatus;
|
||||
|
||||
@JsonProperty("NetworkStatus")
|
||||
private NetworkStatus networkStatus;
|
||||
|
||||
@JsonProperty("DiskStatus")
|
||||
private DiskStatus diskStatus;
|
||||
|
||||
}
|
||||
53
server/src/main/java/io/wdd/rpc/status/beans/CPUMetric.java
Normal file
53
server/src/main/java/io/wdd/rpc/status/beans/CPUMetric.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package io.wdd.rpc.status.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class CPUMetric {
|
||||
|
||||
/**
|
||||
* numCores
|
||||
*/
|
||||
@JsonProperty("NumCores")
|
||||
private Integer numCores;
|
||||
/**
|
||||
* cPUPercent
|
||||
*/
|
||||
@JsonProperty("CPUPercent")
|
||||
private Double cPUPercent;
|
||||
/**
|
||||
* cPULoads
|
||||
*/
|
||||
@JsonProperty("CPULoads")
|
||||
private CPULoadsDTO cPULoads;
|
||||
|
||||
/**
|
||||
* CPULoadsDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class CPULoadsDTO {
|
||||
/**
|
||||
* load1
|
||||
*/
|
||||
@JsonProperty("load1")
|
||||
private Double load1;
|
||||
/**
|
||||
* load5
|
||||
*/
|
||||
@JsonProperty("load5")
|
||||
private Double load5;
|
||||
/**
|
||||
* load15
|
||||
*/
|
||||
@JsonProperty("load15")
|
||||
private Double load15;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package io.wdd.rpc.status.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class CPUStatus {
|
||||
|
||||
|
||||
@JsonProperty("NumCores")
|
||||
private Integer numCores;
|
||||
@JsonProperty("CPUInfo")
|
||||
private List<CPUInfoDTO> cPUInfo;
|
||||
@JsonProperty("CPUPercent")
|
||||
private Double cPUPercent;
|
||||
@JsonProperty("CPULoads")
|
||||
private CPULoadsDTO cPULoads;
|
||||
@JsonProperty("SystemLoads")
|
||||
private SystemLoadsDTO systemLoads;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class CPULoadsDTO {
|
||||
@JsonProperty("load1")
|
||||
private Integer load1;
|
||||
@JsonProperty("load5")
|
||||
private Integer load5;
|
||||
@JsonProperty("load15")
|
||||
private Integer load15;
|
||||
}
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class SystemLoadsDTO {
|
||||
@JsonProperty("load1")
|
||||
private Integer load1;
|
||||
@JsonProperty("load5")
|
||||
private Integer load5;
|
||||
@JsonProperty("load15")
|
||||
private Integer load15;
|
||||
}
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class CPUInfoDTO {
|
||||
@JsonProperty("cpu")
|
||||
private Integer cpu;
|
||||
@JsonProperty("vendorId")
|
||||
private String vendorId;
|
||||
@JsonProperty("family")
|
||||
private String family;
|
||||
@JsonProperty("model")
|
||||
private String model;
|
||||
@JsonProperty("stepping")
|
||||
private Integer stepping;
|
||||
@JsonProperty("physicalId")
|
||||
private String physicalId;
|
||||
@JsonProperty("coreId")
|
||||
private String coreId;
|
||||
@JsonProperty("cores")
|
||||
private Integer cores;
|
||||
@JsonProperty("modelName")
|
||||
private String modelName;
|
||||
@JsonProperty("mhz")
|
||||
private Integer mhz;
|
||||
@JsonProperty("cacheSize")
|
||||
private Integer cacheSize;
|
||||
@JsonProperty("flags")
|
||||
private List<?> flags;
|
||||
@JsonProperty("microcode")
|
||||
private String microcode;
|
||||
}
|
||||
}
|
||||
47
server/src/main/java/io/wdd/rpc/status/beans/DiskInfo.java
Normal file
47
server/src/main/java/io/wdd/rpc/status/beans/DiskInfo.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package io.wdd.rpc.status.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class DiskInfo {
|
||||
|
||||
|
||||
/**
|
||||
* device
|
||||
*/
|
||||
@JsonProperty("device")
|
||||
private String device;
|
||||
/**
|
||||
* mountpoint
|
||||
*/
|
||||
@JsonProperty("mountpoint")
|
||||
private String mountpoint;
|
||||
/**
|
||||
* fstype
|
||||
*/
|
||||
@JsonProperty("fstype")
|
||||
private String fstype;
|
||||
/**
|
||||
* total
|
||||
*/
|
||||
@JsonProperty("total")
|
||||
private Long total;
|
||||
/**
|
||||
* free
|
||||
*/
|
||||
@JsonProperty("free")
|
||||
private Long free;
|
||||
/**
|
||||
* used
|
||||
*/
|
||||
@JsonProperty("used")
|
||||
private Long used;
|
||||
/**
|
||||
* usedPercent
|
||||
*/
|
||||
@JsonProperty("usedPercent")
|
||||
private Double usedPercent;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package io.wdd.rpc.status.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class DiskStatus {
|
||||
|
||||
@JsonProperty("Total")
|
||||
private Long total;
|
||||
@JsonProperty("Used")
|
||||
private Long used;
|
||||
// @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;
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package io.wdd.rpc.status.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class DockerMetric {
|
||||
|
||||
|
||||
/**
|
||||
* dockerStats
|
||||
*/
|
||||
@JsonProperty("DockerStats")
|
||||
private List<DockerStatsDTO> dockerStats;
|
||||
|
||||
/**
|
||||
* DockerStatsDTO
|
||||
*/
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public static class DockerStatsDTO {
|
||||
/**
|
||||
* containerID
|
||||
*/
|
||||
@JsonProperty("containerID")
|
||||
private String containerID;
|
||||
/**
|
||||
* name
|
||||
*/
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
/**
|
||||
* image
|
||||
*/
|
||||
@JsonProperty("image")
|
||||
private String image;
|
||||
/**
|
||||
* status
|
||||
*/
|
||||
@JsonProperty("status")
|
||||
private String status;
|
||||
/**
|
||||
* running
|
||||
*/
|
||||
@JsonProperty("running")
|
||||
private Boolean running;
|
||||
}
|
||||
}
|
||||
@@ -6,16 +6,33 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class MemoryStatus {
|
||||
public class MemoryMetric {
|
||||
|
||||
|
||||
/**
|
||||
* totalMemory
|
||||
*/
|
||||
@JsonProperty("TotalMemory")
|
||||
private Long totalMemory;
|
||||
@JsonProperty("UsedMemory")
|
||||
private Long usedMemory;
|
||||
/**
|
||||
* availableMemory
|
||||
*/
|
||||
@JsonProperty("AvailableMemory")
|
||||
private Long availableMemory;
|
||||
@JsonProperty("TotalVirtualMemory")
|
||||
private Long totalVirtualMemory;
|
||||
@JsonProperty("UsedVirtualMemory")
|
||||
private Long usedVirtualMemory;
|
||||
/**
|
||||
* usedMemory
|
||||
*/
|
||||
@JsonProperty("UsedMemory")
|
||||
private Long usedMemory;
|
||||
/**
|
||||
* usedPercent
|
||||
*/
|
||||
@JsonProperty("usedPercent")
|
||||
private Double usedPercent;
|
||||
/**
|
||||
* free
|
||||
*/
|
||||
@JsonProperty("free")
|
||||
private Long free;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package io.wdd.rpc.status.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class NetworkMetric {
|
||||
|
||||
/**
|
||||
* name
|
||||
*/
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
/**
|
||||
* bytesSent
|
||||
*/
|
||||
@JsonProperty("bytesSent")
|
||||
private Integer bytesSent;
|
||||
/**
|
||||
* bytesRecv
|
||||
*/
|
||||
@JsonProperty("bytesRecv")
|
||||
private Integer bytesRecv;
|
||||
/**
|
||||
* packetsSent
|
||||
*/
|
||||
@JsonProperty("packetsSent")
|
||||
private Integer packetsSent;
|
||||
/**
|
||||
* packetsRecv
|
||||
*/
|
||||
@JsonProperty("packetsRecv")
|
||||
private Integer packetsRecv;
|
||||
/**
|
||||
* errin
|
||||
*/
|
||||
@JsonProperty("errin")
|
||||
private Integer errin;
|
||||
/**
|
||||
* errout
|
||||
*/
|
||||
@JsonProperty("errout")
|
||||
private Integer errout;
|
||||
/**
|
||||
* dropin
|
||||
*/
|
||||
@JsonProperty("dropin")
|
||||
private Integer dropin;
|
||||
/**
|
||||
* dropout
|
||||
*/
|
||||
@JsonProperty("dropout")
|
||||
private Integer dropout;
|
||||
/**
|
||||
* fifoin
|
||||
*/
|
||||
@JsonProperty("fifoin")
|
||||
private Integer fifoin;
|
||||
/**
|
||||
* fifoout
|
||||
*/
|
||||
@JsonProperty("fifoout")
|
||||
private Integer fifoout;
|
||||
/**
|
||||
* sendSpeed
|
||||
*/
|
||||
@JsonProperty("SendSpeed")
|
||||
private Double sendSpeed;
|
||||
/**
|
||||
* recvSpeed
|
||||
*/
|
||||
@JsonProperty("RecvSpeed")
|
||||
private Double recvSpeed;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package io.wdd.rpc.status.beans;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class NetworkStatus {
|
||||
|
||||
@JsonProperty("name")
|
||||
private String name;
|
||||
@JsonProperty("internal_ip_v4")
|
||||
private List<String> internalIpV4;
|
||||
@JsonProperty("internal_ip_v6")
|
||||
private List<String> internalIpV6;
|
||||
@JsonProperty("mac")
|
||||
private String mac;
|
||||
@JsonProperty("sent")
|
||||
private Long sent;
|
||||
@JsonProperty("recv")
|
||||
private Long recv;
|
||||
@JsonProperty("sent_rate")
|
||||
private String sentRate;
|
||||
@JsonProperty("recv_rate")
|
||||
private String recvRate;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package io.wdd.rpc.status.service;
|
||||
|
||||
import io.wdd.rpc.beans.request.MetricQueryEntity;
|
||||
import io.wdd.rpc.status.beans.AgentStatus;
|
||||
import io.wdd.rpc.status.beans.AgentMetric;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -16,7 +16,7 @@ public interface SyncStatusService {
|
||||
* @param aliveStatusWaitMaxTime
|
||||
* @return
|
||||
*/
|
||||
Map<String, Boolean> SyncCollectAgentAliveStatus(List<String> agentTopicNameList, int aliveStatusWaitMaxTime);
|
||||
Map<String, Boolean> SyncCheckAgentIsAlive(List<String> agentTopicNameList, int aliveStatusWaitMaxTime);
|
||||
|
||||
/**
|
||||
* 同步收集 节点的运行状态
|
||||
@@ -25,7 +25,7 @@ public interface SyncStatusService {
|
||||
* @param collectMetricWaitMaxTime
|
||||
* @return
|
||||
*/
|
||||
Map<String, AgentStatus> SyncCollectAgentMetricStatus(List<String> agentTopicNameList, int collectMetricWaitMaxTime);
|
||||
Map<String, AgentMetric> SyncCollectAgentMetricStatus(List<String> agentTopicNameList, int collectMetricWaitMaxTime);
|
||||
|
||||
|
||||
/* Metric 调用的后端接口 */
|
||||
@@ -35,6 +35,6 @@ public interface SyncStatusService {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
ArrayList<AgentStatus> QueryMetricStatus(MetricQueryEntity metricQueryEntity);
|
||||
ArrayList<AgentMetric> QueryMetricStatus(MetricQueryEntity metricQueryEntity);
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ServerInfoPO implements Serializable {
|
||||
/**
|
||||
* server primary key
|
||||
*/
|
||||
@TableId(value = "server_id", type = IdType.ASSIGN_ID)
|
||||
@TableId(value = "server_id", type = IdType.AUTO)
|
||||
private Long serverId;
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,6 +14,7 @@ public interface CoreServerService {
|
||||
|
||||
List<ServerInfoVO> serverGetSingle(String serverName, String ipv4, String serverLocation);
|
||||
|
||||
// list all server that are not deleted
|
||||
List<ServerInfoPO> serverGetAll();
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,31 +27,23 @@ spring:
|
||||
port: 21370
|
||||
database: 0
|
||||
password: boge8tingH
|
||||
# cluster:
|
||||
# nodes:
|
||||
# - 43.154.83.213:21370
|
||||
# - 43.154.83.213:21371
|
||||
# - 43.154.83.213:21372
|
||||
# - 43.154.83.213:21373
|
||||
# - 43.154.83.213:21374
|
||||
# - 43.154.83.213:21375
|
||||
# # 获取失败 最大重定向次数
|
||||
# max-redirects: 3
|
||||
# timeout: 50000
|
||||
timeout: 50000
|
||||
#如果用以前的jedis,可以把下面的lettuce换成jedis即可
|
||||
lettuce:
|
||||
jedis:
|
||||
pool:
|
||||
# 连接池最大连接数默认值为8
|
||||
max-active: 16
|
||||
# 连接池最大阻塞时间(使用负值表示没有限制)默认值为-1
|
||||
max-wait: -1
|
||||
max-wait: 1000
|
||||
# 连接池中最大空闲连接数默认值为8
|
||||
max-idle: 10
|
||||
max-idle: 16
|
||||
# 连接池中的最小空闲连接数,默认值为0
|
||||
min-idle: 10
|
||||
min-idle: 4
|
||||
time-between-eviction-runs: 50000
|
||||
|
||||
|
||||
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://10.250.0.100:21306/octopus_server?autoReconnect=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
|
||||
|
||||
@@ -55,7 +55,7 @@ public class TestBaseFuncScheduler {
|
||||
|
||||
// baseFuncScheduler.runProcedure(projectDeployContext);
|
||||
|
||||
// harborFuncScheduler.runProcedure(projectDeployContext);
|
||||
harborFuncScheduler.runProcedure(projectDeployContext);
|
||||
|
||||
appFuncScheduler.runProcedure(projectDeployContext);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user