[Octopus] modify project to SpringBoot version
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* AgentHealthy状态描述实体类
|
||||
* Agent存货状态描述
|
||||
*/
|
||||
@Getter
|
||||
public enum AgentHealthyStatusEnum {
|
||||
|
||||
FAILED("FAILED", "Agent存活状态为 失败"),
|
||||
|
||||
HEALTHY("HEALTHY", "Agent存活状态为 存活"),
|
||||
|
||||
UNKNOWN("UNKNOWN", "Agent存活状态 未知");
|
||||
|
||||
String status;
|
||||
|
||||
String description;
|
||||
|
||||
|
||||
AgentHealthyStatusEnum(String status, String description) {
|
||||
this.description = description;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
41
server/src/main/java/io/wdd/rpc/status/AgentStatus.java
Normal file
41
server/src/main/java/io/wdd/rpc/status/AgentStatus.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
|
||||
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 AgentStatus {
|
||||
|
||||
private static final String AGENT_STATUS_KEY_SUFFIX = "-Status";
|
||||
|
||||
public static String getRedisStatusKey(String agentTopicName) {
|
||||
return agentTopicName+AGENT_STATUS_KEY_SUFFIX;
|
||||
}
|
||||
|
||||
String time;
|
||||
|
||||
String agentName;
|
||||
|
||||
String agentTopicName;
|
||||
|
||||
CpuInfo cpuInfo;
|
||||
|
||||
MemoryInfo memoryInfo;
|
||||
|
||||
List<DiskInfo> diskStoreInfo;
|
||||
|
||||
List<NetworkInfo> networkInfo;
|
||||
|
||||
AgentSystemInfo osInfo;
|
||||
|
||||
AppStatusInfo appStatus;
|
||||
|
||||
}
|
||||
48
server/src/main/java/io/wdd/rpc/status/AgentSystemInfo.java
Normal file
48
server/src/main/java/io/wdd/rpc/status/AgentSystemInfo.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
import io.wdd.common.utils.TimeUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import oshi.software.os.OperatingSystem;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class AgentSystemInfo {
|
||||
|
||||
String osInfo;
|
||||
|
||||
String family;
|
||||
|
||||
String manufacturer;
|
||||
|
||||
String bootTime;
|
||||
|
||||
String upTime;
|
||||
|
||||
public static AgentSystemInfo mapFromOHSISystem(OperatingSystem os) {
|
||||
|
||||
return AgentSystemInfo.builder()
|
||||
.osInfo(String.valueOf(os.getVersionInfo()))
|
||||
.family(os.getFamily())
|
||||
.manufacturer(os.getManufacturer())
|
||||
.bootTime(TimeUtils.localDateTimeString(
|
||||
LocalDateTime.ofInstant(
|
||||
Instant.ofEpochSecond(os.getSystemBootTime()),
|
||||
ZoneId.of("UTC+8")
|
||||
)
|
||||
))
|
||||
.upTime(TimeUtils.toRelative(os.getSystemUptime()*1000, 3))
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
28
server/src/main/java/io/wdd/rpc/status/AppStatusEnum.java
Normal file
28
server/src/main/java/io/wdd/rpc/status/AppStatusEnum.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package io.wdd.rpc.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;
|
||||
}
|
||||
|
||||
}
|
||||
22
server/src/main/java/io/wdd/rpc/status/AppStatusInfo.java
Normal file
22
server/src/main/java/io/wdd/rpc/status/AppStatusInfo.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package io.wdd.rpc.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;
|
||||
|
||||
}
|
||||
192
server/src/main/java/io/wdd/rpc/status/CpuInfo.java
Normal file
192
server/src/main/java/io/wdd/rpc/status/CpuInfo.java
Normal file
@@ -0,0 +1,192 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class CpuInfo {
|
||||
|
||||
|
||||
private static final DecimalFormat LOAD_FORMAT = new DecimalFormat("#.00");
|
||||
private static final double GHZ_UNIT = 1000000000d;
|
||||
|
||||
/**
|
||||
* CPU总线程
|
||||
*/
|
||||
private Integer cpuTotal;
|
||||
|
||||
/**
|
||||
* CPU核心数
|
||||
*/
|
||||
private Integer coreTotal;
|
||||
|
||||
/**
|
||||
* CPU总数 计算方式理论上为 cpuTotal * 100
|
||||
*/
|
||||
private double cpuUsageTotol;
|
||||
|
||||
/**
|
||||
* CPU系统使用率
|
||||
*/
|
||||
private double systemCpuUsage;
|
||||
|
||||
/**
|
||||
* CPU用户使用率
|
||||
*/
|
||||
private double userCpuUsage;
|
||||
|
||||
/**
|
||||
* CPU当前等待率
|
||||
*/
|
||||
private double wait;
|
||||
|
||||
/**
|
||||
* CPU当前空闲率
|
||||
*/
|
||||
private double free;
|
||||
|
||||
/**
|
||||
* CPU型号信息
|
||||
*/
|
||||
private CpuModel cpuModel;
|
||||
|
||||
private double maxFreq;
|
||||
|
||||
private double[] runFreq;
|
||||
|
||||
private double[] cpuLoadAverage;
|
||||
|
||||
private double[] systemLoadAverage;
|
||||
|
||||
public CpuInfo(CentralProcessor processor, long waitingTime) {
|
||||
this.init(processor, waitingTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取每个CPU核心的tick,计算方式为 100 * tick / totalCpu
|
||||
*
|
||||
* @param tick tick
|
||||
* @param totalCpu CPU总数
|
||||
* @return 平均每个CPU核心的tick
|
||||
* @since 5.7.12
|
||||
*/
|
||||
private static double formatDouble(long tick, long totalCpu) {
|
||||
if (0 == totalCpu) {
|
||||
return 0D;
|
||||
}
|
||||
return Double.parseDouble(LOAD_FORMAT.format(tick <= 0 ? 0 : (100d * tick / totalCpu)));
|
||||
}
|
||||
|
||||
private static double formatDouble(double doubleNum) {
|
||||
|
||||
return Double.parseDouble(LOAD_FORMAT.format(doubleNum));
|
||||
}
|
||||
|
||||
private static double[] formatCpuLoadAverage(double[] cpuLoadAverage) {
|
||||
double[] result = new double[cpuLoadAverage.length];
|
||||
|
||||
for (int i = 0; i < cpuLoadAverage.length; i++) {
|
||||
result[i] = formatDouble(cpuLoadAverage[i]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static double formatCpuFrequency(long freq){
|
||||
|
||||
return Double.parseDouble(LOAD_FORMAT.format(freq / GHZ_UNIT));
|
||||
}
|
||||
|
||||
private static double[] formatCpuFrequencyList(long[] freqList){
|
||||
|
||||
int length = freqList.length;
|
||||
double[] result = new double[length];
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
result[i] = formatCpuFrequency(freqList[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定等待时间内系统CPU 系统使用率、用户使用率、利用率等等 相关信息
|
||||
*
|
||||
* @param processor {@link CentralProcessor}
|
||||
* @param waitingTime 设置等待时间,单位毫秒
|
||||
* @since 5.7.12
|
||||
*/
|
||||
private void init(CentralProcessor processor, long waitingTime) {
|
||||
|
||||
final CpuTicks ticks = new CpuTicks(processor, waitingTime);
|
||||
//this.ticks = ticks;
|
||||
|
||||
// base core info
|
||||
this.cpuTotal = processor.getLogicalProcessorCount();
|
||||
this.coreTotal = processor.getPhysicalProcessorCount();
|
||||
|
||||
// cpu information
|
||||
this.cpuModel = mapFromProcessorIdentifier(processor.getProcessorIdentifier());
|
||||
|
||||
final long totalCpu = ticks.totalCpu();
|
||||
this.cpuUsageTotol = totalCpu;
|
||||
|
||||
// cpu frequency
|
||||
this.maxFreq = formatCpuFrequency(processor.getMaxFreq());
|
||||
this.runFreq = formatCpuFrequencyList(processor.getCurrentFreq());
|
||||
|
||||
// cpu usage
|
||||
this.systemCpuUsage = formatDouble(ticks.cSys, totalCpu);
|
||||
this.userCpuUsage = formatDouble(ticks.user, totalCpu);
|
||||
this.wait = formatDouble(ticks.ioWait, totalCpu);
|
||||
this.free = formatDouble(ticks.idle, totalCpu);
|
||||
|
||||
// system load average
|
||||
this.systemLoadAverage = processor.getSystemLoadAverage(3);
|
||||
|
||||
// cpu load average
|
||||
this.cpuLoadAverage = formatCpuLoadAverage(processor.getProcessorCpuLoad(waitingTime));
|
||||
|
||||
}
|
||||
|
||||
private CpuModel mapFromProcessorIdentifier(CentralProcessor.ProcessorIdentifier id) {
|
||||
|
||||
return CpuModel.builder()
|
||||
.cpu64bit(id.isCpu64bit())
|
||||
.name(id.getName())
|
||||
.identifier(id.getIdentifier())
|
||||
.microArch(id.getMicroarchitecture())
|
||||
.vendor(id.getVendor())
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* CPU型号信息
|
||||
*/
|
||||
//private CpuTicks ticks;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
private static class CpuModel {
|
||||
String name;
|
||||
|
||||
String vendor;
|
||||
|
||||
String microArch;
|
||||
|
||||
boolean cpu64bit;
|
||||
|
||||
String identifier;
|
||||
}
|
||||
|
||||
}
|
||||
99
server/src/main/java/io/wdd/rpc/status/CpuTicks.java
Normal file
99
server/src/main/java/io/wdd/rpc/status/CpuTicks.java
Normal file
@@ -0,0 +1,99 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.util.Util;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CpuTicks {
|
||||
|
||||
long idle;
|
||||
|
||||
long nice;
|
||||
|
||||
long irq;
|
||||
|
||||
long softIrq;
|
||||
|
||||
long steal;
|
||||
|
||||
long cSys;
|
||||
|
||||
long user;
|
||||
|
||||
long ioWait;
|
||||
|
||||
private static int IDLEIndex;
|
||||
private static int NICEIndex;
|
||||
private static int IRQIndex;
|
||||
private static int SOFTIRQIndex;
|
||||
private static int STEALIndex;
|
||||
private static int SYSTEMIndex;
|
||||
private static int USERIndex;
|
||||
private static int IOWAITIndex;
|
||||
|
||||
static {
|
||||
|
||||
IDLEIndex = CentralProcessor.TickType.IDLE.getIndex();
|
||||
NICEIndex = CentralProcessor.TickType.NICE.getIndex();
|
||||
IRQIndex =CentralProcessor.TickType.IRQ.getIndex();
|
||||
SOFTIRQIndex = CentralProcessor.TickType.SOFTIRQ.getIndex();
|
||||
STEALIndex = CentralProcessor.TickType.STEAL.getIndex();
|
||||
SYSTEMIndex = CentralProcessor.TickType.SYSTEM.getIndex();
|
||||
USERIndex = CentralProcessor.TickType.USER.getIndex();
|
||||
IOWAITIndex = CentralProcessor.TickType.IOWAIT.getIndex();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造,等待时间为用于计算在一定时长内的CPU负载情况,如传入1000表示最近1秒的负载情况
|
||||
*
|
||||
* @param processor {@link CentralProcessor}
|
||||
* @param waitingTime 设置等待时间,单位毫秒
|
||||
*/
|
||||
public CpuTicks(CentralProcessor processor, long waitingTime) {
|
||||
// CPU信息
|
||||
final long[] prevTicks = processor.getSystemCpuLoadTicks();
|
||||
|
||||
// 这里必须要设置延迟
|
||||
Util.sleep(waitingTime);
|
||||
final long[] ticks = processor.getSystemCpuLoadTicks();
|
||||
|
||||
this.idle = tick(prevTicks, ticks, IDLEIndex);
|
||||
this.nice = tick(prevTicks, ticks, NICEIndex);
|
||||
this.irq = tick(prevTicks, ticks, IRQIndex);
|
||||
this.softIrq = tick(prevTicks, ticks, SOFTIRQIndex);
|
||||
this.steal = tick(prevTicks, ticks, STEALIndex);
|
||||
this.cSys = tick(prevTicks, ticks, SYSTEMIndex);
|
||||
this.user = tick(prevTicks, ticks, USERIndex);
|
||||
this.ioWait = tick(prevTicks, ticks, IOWAITIndex);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取CPU总的使用率
|
||||
*
|
||||
* @return CPU总使用率
|
||||
*/
|
||||
public long totalCpu() {
|
||||
return Math.max(user + nice + cSys + idle + ioWait + irq + softIrq + steal, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一段时间内的CPU负载标记差
|
||||
*
|
||||
* @param prevTicks 开始的ticks
|
||||
* @param ticks 结束的ticks
|
||||
* @param tickType tick类型
|
||||
* @return 标记差
|
||||
* @since 5.7.12
|
||||
*/
|
||||
private static long tick(long[] prevTicks, long[] ticks, int index) {
|
||||
return ticks[index] - prevTicks[index];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
71
server/src/main/java/io/wdd/rpc/status/DiskInfo.java
Normal file
71
server/src/main/java/io/wdd/rpc/status/DiskInfo.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
import io.wdd.common.utils.FormatUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import oshi.hardware.HWDiskStore;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class DiskInfo {
|
||||
|
||||
String name;
|
||||
|
||||
String model;
|
||||
|
||||
String serial;
|
||||
|
||||
String size;
|
||||
|
||||
|
||||
private List<PartitionInfo> partitionInfoList;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
private static class PartitionInfo{
|
||||
|
||||
String path;
|
||||
|
||||
String type;
|
||||
|
||||
String size;
|
||||
|
||||
String mountPoint;
|
||||
|
||||
}
|
||||
|
||||
public static List<DiskInfo> mapFromDiskStore(List<HWDiskStore> hwDiskStoreList){
|
||||
|
||||
return hwDiskStoreList.stream().map(
|
||||
hwDiskStore -> DiskInfo.builder()
|
||||
.name(hwDiskStore.getName())
|
||||
.model(hwDiskStore.getModel())
|
||||
.serial(hwDiskStore.getSerial())
|
||||
.size(FormatUtils.formatData(hwDiskStore.getSize()))
|
||||
.partitionInfoList(
|
||||
// partition should also be got from stream
|
||||
hwDiskStore.getPartitions().stream().map(partition -> DiskInfo.PartitionInfo.builder()
|
||||
.path(partition.getIdentification())
|
||||
.size(FormatUtils.formatData(partition.getSize()))
|
||||
.type(partition.getType())
|
||||
.mountPoint(partition.getMountPoint())
|
||||
.build()
|
||||
).collect(Collectors.toList())
|
||||
)
|
||||
.build()
|
||||
).collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
47
server/src/main/java/io/wdd/rpc/status/MemoryInfo.java
Normal file
47
server/src/main/java/io/wdd/rpc/status/MemoryInfo.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
import io.wdd.common.utils.FormatUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import oshi.hardware.GlobalMemory;
|
||||
import oshi.hardware.VirtualMemory;
|
||||
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class MemoryInfo {
|
||||
|
||||
|
||||
String total;
|
||||
|
||||
String usage;
|
||||
|
||||
String available;
|
||||
|
||||
String memoryType;
|
||||
|
||||
String swapTotal;
|
||||
|
||||
String swapAvailable;
|
||||
|
||||
String swapUsage;
|
||||
|
||||
public static MemoryInfo build(GlobalMemory memory) {
|
||||
|
||||
VirtualMemory virtualMemory = memory.getVirtualMemory();
|
||||
return MemoryInfo.builder()
|
||||
.memoryType(memory.getPhysicalMemory().get(0).getMemoryType())
|
||||
.total(FormatUtils.formatData(memory.getTotal()))
|
||||
.available(FormatUtils.formatData(memory.getAvailable()))
|
||||
.usage(FormatUtils.formatData(memory.getTotal() - memory.getAvailable()))
|
||||
.swapTotal(FormatUtils.formatData(virtualMemory.getSwapTotal()))
|
||||
.swapUsage(FormatUtils.formatData(virtualMemory.getSwapUsed()))
|
||||
.swapAvailable(FormatUtils.formatData(virtualMemory.getSwapTotal() - virtualMemory.getSwapUsed()))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
18
server/src/main/java/io/wdd/rpc/status/MetricStatus.java
Normal file
18
server/src/main/java/io/wdd/rpc/status/MetricStatus.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 没时间整这些,反正大一点数据也无所谓 不是吗
|
||||
*/
|
||||
@Deprecated
|
||||
@Data
|
||||
public class MetricStatus {
|
||||
|
||||
CpuInfo cpuInfo;
|
||||
|
||||
MemoryInfo memoryInfo;
|
||||
|
||||
AppStatusInfo appStatus;
|
||||
|
||||
}
|
||||
108
server/src/main/java/io/wdd/rpc/status/NetworkInfo.java
Normal file
108
server/src/main/java/io/wdd/rpc/status/NetworkInfo.java
Normal file
@@ -0,0 +1,108 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
|
||||
import io.wdd.common.utils.FormatUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import oshi.hardware.NetworkIF;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class NetworkInfo {
|
||||
|
||||
private String name;
|
||||
private String displayName;
|
||||
private String macAddr;
|
||||
private String mtu;
|
||||
private String[] innerIpv4Addr;
|
||||
private String publicIpv4Addr;
|
||||
private String[] innerIpv6Addr;
|
||||
private String publicIpv6Addr;
|
||||
/**
|
||||
* 过去1s内的网速,接收速率
|
||||
*/
|
||||
private String recvSpeed;
|
||||
/**
|
||||
* 过去1s内的网速,发送速率
|
||||
*/
|
||||
private String sendSpeed;
|
||||
private String trafficRecv;
|
||||
private String trafficSend;
|
||||
|
||||
public static NetworkInfo mapFromNetworkIF(NetworkIF networkIF) {
|
||||
|
||||
return NetworkInfo
|
||||
.builder()
|
||||
.name(networkIF.getName())
|
||||
.displayName(networkIF.getDisplayName())
|
||||
.mtu(String.valueOf(networkIF.getMTU()))
|
||||
.macAddr(networkIF.getMacaddr())
|
||||
.innerIpv4Addr(generateIPDICRFromNetworkIFList(
|
||||
networkIF,
|
||||
4
|
||||
))
|
||||
.innerIpv6Addr(generateIPDICRFromNetworkIFList(
|
||||
networkIF,
|
||||
6
|
||||
))
|
||||
.trafficSend(FormatUtils.formatData(networkIF.getBytesSent()))
|
||||
.trafficRecv(FormatUtils.formatData(networkIF.getBytesRecv())
|
||||
)
|
||||
.build();
|
||||
|
||||
}
|
||||
public static List<NetworkInfo> mapFromNetworkIFS(List<NetworkIF> networkIFList) {
|
||||
|
||||
return networkIFList
|
||||
.stream()
|
||||
.map(
|
||||
networkIF -> NetworkInfo
|
||||
.builder()
|
||||
.name(networkIF.getName())
|
||||
.displayName(networkIF.getDisplayName())
|
||||
.mtu(String.valueOf(networkIF.getMTU()))
|
||||
.macAddr(networkIF.getMacaddr())
|
||||
.innerIpv4Addr(generateIPDICRFromNetworkIFList(
|
||||
networkIF,
|
||||
4
|
||||
))
|
||||
.innerIpv6Addr(generateIPDICRFromNetworkIFList(
|
||||
networkIF,
|
||||
6
|
||||
))
|
||||
.trafficSend(FormatUtils.formatData(networkIF.getBytesSent()))
|
||||
.trafficRecv(FormatUtils.formatData(networkIF.getBytesRecv())
|
||||
)
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static String[] generateIPDICRFromNetworkIFList(NetworkIF networkIF, int Ipv4OrIpv6) {
|
||||
|
||||
String[] iPAddr;
|
||||
Short[] subnetMasks;
|
||||
|
||||
if (Ipv4OrIpv6 == 4) {
|
||||
iPAddr = networkIF.getIPv4addr();
|
||||
subnetMasks = networkIF.getSubnetMasks();
|
||||
} else {
|
||||
iPAddr = networkIF.getIPv6addr();
|
||||
subnetMasks = networkIF.getPrefixLengths();
|
||||
}
|
||||
|
||||
String[] result = new String[iPAddr.length];
|
||||
for (int index = 0; index < iPAddr.length; index++) {
|
||||
result[index] = iPAddr[index] + "/" + subnetMasks[index];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package io.wdd.rpc.status;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@SuperBuilder(toBuilder = true)
|
||||
public class OctopusStatusMessage {
|
||||
|
||||
// below two will be used by both server and agent
|
||||
// 存储所有Agent的实时健康状态, 1代表健康 0代表失败
|
||||
public static final String ALL_AGENT_STATUS_REDIS_KEY = "ALL_AGENT_HEALTHY_STATUS";
|
||||
public static final String HEALTHY_STATUS_MESSAGE_TYPE = "ping";
|
||||
public static final String ALL_STATUS_MESSAGE_TYPE = "all";
|
||||
public static final String METRIC_STATUS_MESSAGE_TYPE = "metric";
|
||||
public static final String APP_STATUS_MESSAGE_TYPE = "app";
|
||||
|
||||
/**
|
||||
* which kind of status should be return
|
||||
* metric => short time message
|
||||
* all => all agent status message
|
||||
* healthy => check for healthy
|
||||
* */
|
||||
String type;
|
||||
|
||||
String agentTopicName;
|
||||
|
||||
int metricRepeatCount;
|
||||
|
||||
int metricRepeatPinch;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user