[ server ] - agent runtime metric status - 1
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
|
||||
import io.wdd.common.beans.status.OctopusStatusMessage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.wdd.common.beans.status.OctopusStatusMessage.METRIC_STATUS_MESSAGE_TYPE;
|
||||
|
||||
/**
|
||||
* 收集OctopusAgent的运行Metric信息
|
||||
* <p>
|
||||
* CPU Memory AppStatus易变信息
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AgentRuntimeMetricStatus {
|
||||
|
||||
public static List<String> ALL_HEALTHY_AGENT_TOPIC_NAMES;
|
||||
|
||||
@Resource
|
||||
CollectAgentStatus collectAgentStatus;
|
||||
|
||||
public void collect(int metricRepeatCount, int metricRepeatPinch) {
|
||||
|
||||
// 检查基础信息
|
||||
if (CollectionUtils.isEmpty(ALL_HEALTHY_AGENT_TOPIC_NAMES)) {
|
||||
log.error("Metric Status Collect Failed ! no ALL_HEALTHY_AGENT_TOPIC_NAMES");
|
||||
}
|
||||
// 构建 OctopusMessage
|
||||
// 只发送一次消息,让Agent循环定时执行任务
|
||||
buildMetricStatusMessageAndSend(metricRepeatCount, metricRepeatPinch);
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
private void buildMetricStatusMessageAndSend(int metricRepeatCount, int metricRepeatPinch) {
|
||||
|
||||
List<OctopusStatusMessage> collect = ALL_HEALTHY_AGENT_TOPIC_NAMES.stream()
|
||||
.map(
|
||||
agentTopicName -> {
|
||||
return OctopusStatusMessage.builder()
|
||||
.type(METRIC_STATUS_MESSAGE_TYPE)
|
||||
.metricRepeatCount(metricRepeatCount)
|
||||
.metricRepeatCount(metricRepeatCount)
|
||||
.agentTopicName(agentTopicName)
|
||||
.build();
|
||||
}
|
||||
).collect(Collectors.toList());
|
||||
|
||||
// send to the next level
|
||||
collectAgentStatus.statusMessageToAgent(collect);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessage;
|
||||
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
|
||||
import io.wdd.common.beans.status.OctopusStatusMessage;
|
||||
@@ -22,14 +24,17 @@ public class CollectAgentStatus {
|
||||
@Resource
|
||||
ToAgentMessageSender toAgentMessageSender;
|
||||
|
||||
@Resource
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
|
||||
public void collectAgentStatus(OctopusStatusMessage statusMessage) {
|
||||
|
||||
this.collectAgentStatusList(List.of(statusMessage));
|
||||
this.statusMessageToAgent(List.of(statusMessage));
|
||||
}
|
||||
|
||||
|
||||
public void collectAgentStatusList(List<OctopusStatusMessage> statusMessageList) {
|
||||
public void statusMessageToAgent(List<OctopusStatusMessage> statusMessageList) {
|
||||
|
||||
// build all the OctopusMessage
|
||||
List<OctopusMessage> octopusMessageList = statusMessageList.stream().map(
|
||||
@@ -43,15 +48,23 @@ public class CollectAgentStatus {
|
||||
toAgentMessageSender.send(octopusMessageList);
|
||||
|
||||
// todo how to get result ?
|
||||
|
||||
}
|
||||
|
||||
private OctopusMessage buildOctopusMessageStatus(OctopusStatusMessage octopusStatusMessage) {
|
||||
|
||||
// must be like this or it will be deserialized as LinkedHashMap
|
||||
String s;
|
||||
try {
|
||||
s = objectMapper.writeValueAsString(octopusStatusMessage);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return OctopusMessage.builder()
|
||||
.uuid(octopusStatusMessage.getAgentTopicName())
|
||||
.type(OctopusMessageType.STATUS)
|
||||
.init_time(TimeUtils.currentTime())
|
||||
.content(octopusStatusMessage)
|
||||
.content(s)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.wdd.common.beans.status.OctopusStatusMessage;
|
||||
import io.wdd.common.utils.TimeUtils;
|
||||
import io.wdd.rpc.scheduler.service.BuildStatusScheduleTask;
|
||||
import io.wdd.rpc.scheduler.service.OctopusQuartzService;
|
||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
||||
import io.wdd.server.coreService.CoreServerService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.Trigger;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.wdd.common.beans.status.OctopusStatusMessage.ALL_AGENT_STATUS_REDIS_KEY;
|
||||
import static io.wdd.common.beans.status.OctopusStatusMessage.HEALTHY_STATUS_MESSAGE_TYPE;
|
||||
import static io.wdd.rpc.status.AgentRuntimeMetricStatus.ALL_HEALTHY_AGENT_TOPIC_NAMES;
|
||||
|
||||
/**
|
||||
* 获取所有注册的Agent
|
||||
@@ -44,6 +51,8 @@ public class MonitorAllAgentStatus {
|
||||
CollectAgentStatus collectAgentStatus;
|
||||
@Resource
|
||||
CoreServerService coreServerService;
|
||||
@Resource
|
||||
BuildStatusScheduleTask buildStatusScheduleTask;
|
||||
|
||||
public void go() {
|
||||
|
||||
@@ -75,7 +84,8 @@ public class MonitorAllAgentStatus {
|
||||
|
||||
private void checkOrCreateRedisHealthyKey() {
|
||||
|
||||
if (!redisTemplate.hasKey(ALL_AGENT_STATUS_REDIS_KEY)) {
|
||||
// must init the cached map && make sure the redis key existed!
|
||||
if (null == AGENT_HEALTHY_INIT_MAP || !redisTemplate.hasKey(ALL_AGENT_STATUS_REDIS_KEY)) {
|
||||
log.info("ALL_AGENT_STATUS_REDIS_KEY not existed , start to create");
|
||||
|
||||
// build the redis all agent healthy map struct
|
||||
@@ -95,13 +105,15 @@ public class MonitorAllAgentStatus {
|
||||
}
|
||||
|
||||
private void buildAndSendAgentHealthMessage() {
|
||||
|
||||
List<OctopusStatusMessage> collect = ALL_AGENT_TOPICNAME_LIST.stream().map(
|
||||
agentTopicName -> OctopusStatusMessage.builder()
|
||||
.agentTopicName(agentTopicName)
|
||||
.type(HEALTHY_STATUS_MESSAGE_TYPE)
|
||||
.build()
|
||||
).collect(Collectors.toList());
|
||||
collectAgentStatus.collectAgentStatusList(collect);
|
||||
|
||||
collectAgentStatus.statusMessageToAgent(collect);
|
||||
}
|
||||
|
||||
private void updateAllAgentHealthyStatus() {
|
||||
@@ -124,6 +136,17 @@ public class MonitorAllAgentStatus {
|
||||
// help gc
|
||||
tmp = null;
|
||||
|
||||
// Trigger调用Agent Metric 任务
|
||||
ArrayList<String> allHealthyAgentTopicNames = new ArrayList<>(32);
|
||||
for (int i = 0; i < statusList.size(); i++) {
|
||||
if (statusList.get(i).equals("1")) {
|
||||
allHealthyAgentTopicNames.add(ALL_AGENT_TOPICNAME_LIST.get(i));
|
||||
}
|
||||
}
|
||||
ALL_HEALTHY_AGENT_TOPIC_NAMES = allHealthyAgentTopicNames;
|
||||
// 执行Metric上报任务
|
||||
buildStatusScheduleTask.buildAgentMetricScheduleTask();
|
||||
|
||||
// update time
|
||||
AGENT_HEALTHY_INIT_MAP.put("updateTime", currentTimeString);
|
||||
// init the healthy map
|
||||
|
||||
Reference in New Issue
Block a user