[ agent ] [status] - app status - 5
This commit is contained in:
@@ -17,7 +17,7 @@ import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import static io.wdd.agent.status.AppStatusCollector.ALL_APP_NEED_TO_MONITOR_STATUS;
|
||||
import static io.wdd.agent.executor.AppStatusExecutor.ALL_APP_NEED_TO_MONITOR_STATUS;
|
||||
|
||||
|
||||
@Component
|
||||
@@ -137,12 +137,10 @@ public class NacosConfigurationCollector {
|
||||
// need to keep update to nacos so need to clear the cache
|
||||
ALL_APP_NEED_TO_MONITOR_STATUS.clear();
|
||||
|
||||
all_app_from_nacos.stream().forEach(
|
||||
app -> {
|
||||
all_app_from_nacos.stream().forEach(app -> {
|
||||
String[] split = app.split("/");
|
||||
ALL_APP_NEED_TO_MONITOR_STATUS.put(split[0], split[1] + ".service");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
log.info("ALL_APP_NEED_TO_MONITOR_STATUS are => {}", ALL_APP_NEED_TO_MONITOR_STATUS);
|
||||
|
||||
|
||||
@@ -7,10 +7,12 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.wdd.agent.status.AppStatusCollector.ALL_APP_NEED_TO_MONITOR_STATUS;
|
||||
import static java.util.stream.Collectors.groupingBy;
|
||||
|
||||
@Service
|
||||
@@ -18,7 +20,10 @@ import static java.util.stream.Collectors.groupingBy;
|
||||
@Lazy
|
||||
public class AppStatusExecutor {
|
||||
|
||||
private static ArrayList<ArrayList<String>> APP_STATUS_CHECK_COMMAND;
|
||||
// storage all the applications agent status should report
|
||||
public static final HashMap<String, String> ALL_APP_NEED_TO_MONITOR_STATUS = new HashMap<>(16);
|
||||
|
||||
private static final ArrayList<ArrayList<String>> APP_STATUS_CHECK_COMMAND;
|
||||
|
||||
static {
|
||||
|
||||
@@ -42,7 +47,7 @@ public class AppStatusExecutor {
|
||||
}
|
||||
|
||||
|
||||
public HashMap<String, Set<String>> checkAppStatus(boolean allAppStatus){
|
||||
public HashMap<String, Set<String>> checkAppStatus(boolean allAppStatus) {
|
||||
|
||||
// check all app status
|
||||
Map<String, List<String[]>> collect = ALL_APP_NEED_TO_MONITOR_STATUS.keySet().stream()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.wdd.agent.executor;
|
||||
|
||||
import io.wdd.agent.executor.config.CommandPipelineBuilder;
|
||||
import io.wdd.common.beans.status.AppStatusEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -13,7 +14,8 @@ import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.wdd.agent.status.AppStatusCollector.ALL_APP_NEED_TO_MONITOR_STATUS;
|
||||
import static io.wdd.agent.executor.AppStatusExecutor.ALL_APP_NEED_TO_MONITOR_STATUS;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class CheckSingleAppStatusCallable implements Callable<String[]> {
|
||||
@@ -48,7 +50,7 @@ public class CheckSingleAppStatusCallable implements Callable<String[]> {
|
||||
if (StringUtils.isNotEmpty(error)) {
|
||||
// app not existed!
|
||||
log.debug("app not installed !");
|
||||
result[0] = "NotInstall";
|
||||
result[0] = AppStatusEnum.NOT_INSTALL.getName();
|
||||
} else {
|
||||
log.debug("app existed! and then check the running status !");
|
||||
// app existed! and then check the running status !
|
||||
@@ -63,11 +65,11 @@ public class CheckSingleAppStatusCallable implements Callable<String[]> {
|
||||
Assert.notNull(appStatusCommandResult, "app status command result is null !");
|
||||
|
||||
if (appStatusCommandResult.startsWith("1")) {
|
||||
result[0] = "Healthy";
|
||||
result[0] = AppStatusEnum.HEALTHY.getName();
|
||||
} else if (appStatusCommandResult.startsWith("0")) {
|
||||
result[0] = "Failure";
|
||||
result[0] = AppStatusEnum.FAILURE.getName();
|
||||
} else {
|
||||
result[0] = "NotInstall";
|
||||
result[0] = AppStatusEnum.NOT_INSTALL.getName();
|
||||
}
|
||||
}
|
||||
log.debug("app [ {} ] status check result is => {} ", appName, resultList);
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.wdd.agent.status;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.wdd.agent.config.beans.init.AgentServerInfo;
|
||||
import io.wdd.agent.executor.AppStatusExecutor;
|
||||
import io.wdd.common.beans.status.*;
|
||||
import io.wdd.common.utils.TimeUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -16,9 +17,7 @@ import oshi.hardware.HardwareAbstractionLayer;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -50,6 +49,9 @@ public class AgentStatusCollector {
|
||||
@Resource
|
||||
AgentServerInfo agentServerInfo;
|
||||
|
||||
@Resource
|
||||
AppStatusExecutor appStatusExecutor;
|
||||
|
||||
public AgentStatus collect() {
|
||||
|
||||
AgentStatus agentStatus = AgentStatusCache.get(0);
|
||||
@@ -76,9 +78,23 @@ public class AgentStatusCollector {
|
||||
/* Time */
|
||||
agentStatus.setTime(TimeUtils.currentTimeString());
|
||||
|
||||
/* App Status */
|
||||
agentStatus.setAppStatus(
|
||||
parseAppStatus(appStatusExecutor.checkAppStatus(true))
|
||||
);
|
||||
|
||||
return agentStatus;
|
||||
}
|
||||
|
||||
private AppStatusInfo parseAppStatus(HashMap<String, Set<String>> checkAppStatus) {
|
||||
|
||||
return AppStatusInfo.builder()
|
||||
.Healthy(checkAppStatus.get(AppStatusEnum.HEALTHY.getName()))
|
||||
.Failure(checkAppStatus.get(AppStatusEnum.FAILURE.getName()))
|
||||
.NotInstall(checkAppStatus.get(AppStatusEnum.NOT_INSTALL.getName()))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* when server first time boot up
|
||||
* the server info are not collected completely
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package io.wdd.agent.status;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AppStatusCollector {
|
||||
|
||||
// storage all the applications agent status should report
|
||||
public static final HashMap<String, String> ALL_APP_NEED_TO_MONITOR_STATUS = new HashMap<>(16);
|
||||
|
||||
/**
|
||||
* not very good
|
||||
* but also a kind of method to dynamically listen to nacos configuration change
|
||||
*/
|
||||
/*@NacosValue(value = "${octopus.agent.status.enable}" , autoRefreshed = true)
|
||||
private String all_app_from_nacos;*
|
||||
|
||||
|
||||
|
||||
/*@NacosConfigListener(
|
||||
groupId = "k3s",
|
||||
dataId = "octopus-agent-k3s.yaml",
|
||||
type = ConfigType.YAML,
|
||||
properties =
|
||||
)
|
||||
public void onMessage(String content){
|
||||
|
||||
log.debug("update octopus-agent nacos config are ==> {} ", content);
|
||||
|
||||
Yaml yaml = new Yaml();
|
||||
Object load = yaml.load(content);
|
||||
|
||||
System.out.println("load = " + load);
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.wdd.agent;
|
||||
|
||||
import io.wdd.agent.executor.AppStatusExecutor;
|
||||
import io.wdd.agent.status.AppStatusCollector;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import lombok.Data;
|
||||
@Data
|
||||
public class R<T> {
|
||||
|
||||
|
||||
int code;
|
||||
|
||||
String msg;
|
||||
|
||||
@@ -10,8 +10,6 @@ public enum ResultStat {
|
||||
|
||||
PARAM_ERROR(1003, "请求参数错误!"),
|
||||
|
||||
|
||||
|
||||
BAD(5001, "all error !");
|
||||
|
||||
int code;
|
||||
|
||||
@@ -5,7 +5,6 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,7 +20,6 @@ public class AgentStatus {
|
||||
|
||||
String agentTopicName;
|
||||
|
||||
|
||||
CpuInfo cpuInfo;
|
||||
|
||||
MemoryInfo memoryInfo;
|
||||
@@ -32,4 +30,6 @@ public class AgentStatus {
|
||||
|
||||
AgentSystemInfo osInfo;
|
||||
|
||||
AppStatusInfo appStatus;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package io.wdd.common.beans.status;
|
||||
|
||||
public enum AppStatusEnum {
|
||||
|
||||
HEALTHY("Healthy", "app is running"),
|
||||
|
||||
FAILURE("Failure", "app is failed"),
|
||||
|
||||
NOT_INSTALL("NotInstall", "app not installed");
|
||||
|
||||
String name;
|
||||
|
||||
String description;
|
||||
|
||||
AppStatusEnum(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package io.wdd.common.beans.status;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class AppStatusInfo {
|
||||
|
||||
Set<String> Healthy;
|
||||
|
||||
Set<String> Failure;
|
||||
|
||||
Set<String> NotInstall;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user