[ server ] - monitor all agent status - 2

This commit is contained in:
zeaslity
2023-01-11 10:52:01 +08:00
parent b7958f5c78
commit 1b17a5cf44
10 changed files with 167 additions and 60 deletions

View File

@@ -1,11 +1,27 @@
package io.wdd.agent.config.message.handler;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.wdd.agent.status.HealthyReporter;
import io.wdd.common.beans.rabbitmq.OctopusMessage;
import io.wdd.common.beans.rabbitmq.OctopusMessageType;
import io.wdd.common.beans.status.OctopusStatusMessage;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import static io.wdd.common.beans.status.OctopusStatusMessage.HEALTHY_STATUS_MESSAGE_TYPE;
@Component
public class OMHandlerStatus extends AbstractOctopusMessageHandler {
@Resource
ObjectMapper objectMapper;
@Resource
HealthyReporter healthyReporter;
@Override
public boolean handle(OctopusMessage octopusMessage) {
@@ -13,6 +29,25 @@ public class OMHandlerStatus extends AbstractOctopusMessageHandler {
return next.handle(octopusMessage);
}
// handle about the status kind
try {
OctopusStatusMessage statusMessage = objectMapper.readValue((String) octopusMessage.getContent(), new TypeReference<OctopusStatusMessage>() {
});
String statusType = statusMessage.getType();
if (statusType.equals(HEALTHY_STATUS_MESSAGE_TYPE)) {
// healthy check
healthyReporter.report();
}
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return true;
}
}

View File

@@ -0,0 +1,40 @@
package io.wdd.agent.status;
import io.wdd.agent.config.beans.init.AgentServerInfo;
import io.wdd.common.utils.TimeUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import static io.wdd.common.beans.status.OctopusStatusMessage.ALL_AGENT_STATUS_REDIS_KEY;
/**
* 1. modify the redis key => ALL_AGENT_STATUS_REDIS_KEY
* 2. the hashmap struct key => agentTopicName
* 3. modify the key to "1"
*/
@Service
@Slf4j
public class HealthyReporter {
@Resource
RedisTemplate redisTemplate;
@Resource
AgentServerInfo agentServerInfo;
public void report(){
redisTemplate.opsForHash().put(
ALL_AGENT_STATUS_REDIS_KEY,
agentServerInfo.getAgentTopicName(),
"1"
);
log.debug("Agent Healthy Check Complete ! Time is => {}", TimeUtils.currentTimeString());
}
}