This is an automated email from the ASF dual-hosted git repository.

wuzhiguo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/bigtop-manager.git


The following commit(s) were added to refs/heads/main by this push:
     new 8a8f7ec  BIGTOP-4238: Collect metrics for disk I/O and file 
descriptors (#83)
8a8f7ec is described below

commit 8a8f7ec7a0cc84ae8b7a08a92d1d480ed58c70ee
Author: chenwentao2024 <[email protected]>
AuthorDate: Sat Oct 19 23:04:40 2024 +0800

    BIGTOP-4238: Collect metrics for disk I/O and file descriptors (#83)
---
 .../bigtop/manager/agent/AgentApplication.java     |   5 +
 .../manager/agent/metrics/MetricsCollector.java    |   4 +
 .../agent/monitoring/AgentHostMonitoring.java      | 111 ++++++++-
 .../server/controller/MonitoringController.java    |  13 ++
 .../manager/server/proxy/PrometheusProxy.java      | 249 +++++++++++++++++++++
 .../manager/server/service/MonitoringService.java  |   4 +
 .../server/service/impl/MonitoringServiceImpl.java |  10 +
 7 files changed, 392 insertions(+), 4 deletions(-)

diff --git 
a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/AgentApplication.java
 
b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/AgentApplication.java
index 3f965a3..bd2c3b6 100644
--- 
a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/AgentApplication.java
+++ 
b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/AgentApplication.java
@@ -53,4 +53,9 @@ public class AgentApplication {
     @Qualifier("memMultiGauge") public MultiGauge memMultiGauge(MeterRegistry 
meterRegistry) {
         return AgentHostMonitoring.newMemMultiGauge(meterRegistry);
     }
+
+    @Bean
+    @Qualifier("diskIOMultiGauge") public MultiGauge 
diskIOMultiGauge(MeterRegistry meterRegistry) {
+        return AgentHostMonitoring.newDiskIOMultiGauge(meterRegistry);
+    }
 }
diff --git 
a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/metrics/MetricsCollector.java
 
b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/metrics/MetricsCollector.java
index e1ef7c2..3053033 100644
--- 
a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/metrics/MetricsCollector.java
+++ 
b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/metrics/MetricsCollector.java
@@ -43,6 +43,9 @@ public class MetricsCollector {
     @Resource
     @Qualifier("cpuMultiGauge") private MultiGauge cpuMultiGauge;
 
+    @Resource
+    @Qualifier("diskIOMultiGauge") private MultiGauge diskIOMultiGauge;
+
     @Async
     @Scheduled(cron = "*/10 * *  * * ?")
     public void collect() {
@@ -54,5 +57,6 @@ public class MetricsCollector {
         AgentHostMonitoring.diskMultiGaugeUpdateData(diskMultiGauge);
         AgentHostMonitoring.memMultiGaugeUpdateData(memMultiGauge);
         AgentHostMonitoring.cpuMultiGaugeUpdateData(cpuMultiGauge);
+        AgentHostMonitoring.diskIOMultiGaugeUpdateData(diskIOMultiGauge);
     }
 }
diff --git 
a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/monitoring/AgentHostMonitoring.java
 
b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/monitoring/AgentHostMonitoring.java
index 703f28b..49138b0 100644
--- 
a/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/monitoring/AgentHostMonitoring.java
+++ 
b/bigtop-manager-agent/src/main/java/org/apache/bigtop/manager/agent/monitoring/AgentHostMonitoring.java
@@ -31,6 +31,7 @@ import lombok.extern.slf4j.Slf4j;
 import oshi.SystemInfo;
 import oshi.hardware.CentralProcessor;
 import oshi.hardware.GlobalMemory;
+import oshi.hardware.HWDiskStore;
 import oshi.hardware.HardwareAbstractionLayer;
 import oshi.hardware.NetworkIF;
 import oshi.software.os.NetworkParams;
@@ -38,6 +39,8 @@ import oshi.software.os.OSFileStore;
 import oshi.software.os.OperatingSystem;
 import oshi.util.Util;
 
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
 import java.net.InetAddress;
 import java.net.InterfaceAddress;
 import java.net.UnknownHostException;
@@ -59,10 +62,18 @@ public class AgentHostMonitoring {
     public static final String DISK_NAME = "diskName";
     public static final String DISK_IDLE = "diskFreeSpace";
     public static final String DISK_TOTAL = "diskTotalSpace";
+    public static final String FILE_OPEN_DESCRIPTOR = "fileOpenDescriptor";
+    public static final String FILE_TOTAL_DESCRIPTOR = "fileTotalDescriptor";
     public static final String CPU_LOAD_AVG_MIN_1 = "cpuLoadAvgMin_1";
     public static final String CPU_LOAD_AVG_MIN_5 = "cpuLoadAvgMin_5";
     public static final String CPU_LOAD_AVG_MIN_15 = "cpuLoadAvgMin_15";
     public static final String CPU_USAGE = "cpuUsage";
+    public static final String PHYSICAL_DISK_NAME = "physicalDiskName";
+    public static final String DISK_READ = "diskRead";
+    public static final String DISK_WRITE = "diskWrite";
+    public static long[] previousReadBytes;
+    public static long[] previousWriteBytes;
+    public static boolean initialized = false;
 
     private static boolean sameSubnet(String ipAddress, String subnetMask, 
String gateway) throws UnknownHostException {
         InetAddress inetAddress = InetAddress.getByName(ipAddress);
@@ -90,22 +101,38 @@ public class AgentHostMonitoring {
         ObjectNode objectNode = json.createObjectNode();
         SystemInfo si = new SystemInfo();
         OperatingSystem operatingSystem = si.getOperatingSystem();
+        OperatingSystemMXBean osBean = 
ManagementFactory.getOperatingSystemMXBean();
         HardwareAbstractionLayer hal = si.getHardware();
 
         NetworkParams networkParams = operatingSystem.getNetworkParams();
         String hostName = networkParams.getHostName();
         String ipv4DefaultGateway = networkParams.getIpv4DefaultGateway();
 
+        // File Descriptor
+        OperatingSystemMXBean operatingSystemMXBean = 
ManagementFactory.getOperatingSystemMXBean();
+        long maxFileDescriptors = -1L;
+        long openFileDescriptors = -1L;
+        if (operatingSystemMXBean instanceof 
com.sun.management.UnixOperatingSystemMXBean) {
+            maxFileDescriptors =
+                    ((com.sun.management.UnixOperatingSystemMXBean) 
operatingSystemMXBean).getMaxFileDescriptorCount();
+            openFileDescriptors =
+                    ((com.sun.management.UnixOperatingSystemMXBean) 
operatingSystemMXBean).getOpenFileDescriptorCount();
+        }
+
         // Agent Host Base Info
         ObjectNode hostInfoNode = json.createObjectNode();
         hostInfoNode
                 .put("hostname", hostName)
-                .put("os", operatingSystem.toString())
+                .put("os", osBean.getName())
+                .put("arch", osBean.getArch())
                 .put("ipv4Gateway", ipv4DefaultGateway)
-                .put("cpu_info", 
hal.getProcessor().getProcessorIdentifier().getMicroarchitecture())
+                // .put("cpu_info", 
hal.getProcessor().getProcessorIdentifier().getMicroarchitecture())
+                .put("cpu_info", 
hal.getProcessor().getProcessorIdentifier().getName())
                 .put("logical_cores", 
hal.getProcessor().getLogicalProcessorCount())
                 .put("physical_cores", 
hal.getProcessor().getPhysicalProcessorCount())
-                .put("iPv4addr", getAgentHostIPv4addr(hal, 
ipv4DefaultGateway));
+                .put("iPv4addr", getAgentHostIPv4addr(hal, ipv4DefaultGateway))
+                .put(FILE_OPEN_DESCRIPTOR, openFileDescriptors)
+                .put(FILE_TOTAL_DESCRIPTOR, maxFileDescriptors);
         objectNode.set(AGENT_BASE_INFO, hostInfoNode);
 
         objectNode.put(BOOT_TIME, operatingSystem.getSystemBootTime());
@@ -122,12 +149,27 @@ public class AgentHostMonitoring {
                 continue;
             }
             ObjectNode disk = json.createObjectNode();
+
             disk.put(DISK_NAME, fileStore.getVolume());
             disk.put(DISK_TOTAL, fileStore.getTotalSpace());
             disk.put(DISK_IDLE, fileStore.getFreeSpace());
+
             diskArrayNode.add(disk);
         }
         objectNode.set(DISKS_BASE_INFO, diskArrayNode);
+        // DISK IO init
+        if (!initialized) {
+            List<HWDiskStore> diskStores = si.getHardware().getDiskStores();
+            previousReadBytes = new long[diskStores.size()];
+            previousWriteBytes = new long[diskStores.size()];
+
+            // init 0
+            for (int i = 0; i < diskStores.size(); i++) {
+                previousReadBytes[i] = 0L;
+                previousWriteBytes[i] = 0L;
+            }
+            initialized = true; // tag
+        }
         return objectNode;
     }
 
@@ -192,7 +234,6 @@ public class AgentHostMonitoring {
             labelValues.put(
                     diskIdleLabelValues,
                     
diskJsonNode.get(AgentHostMonitoring.DISK_IDLE).asDouble());
-
             // Disk Total
             ArrayList<String> diskTotalLabelValues = new 
ArrayList<>(diskGaugeLabelsValues);
             diskTotalLabelValues.add(
@@ -207,6 +248,52 @@ public class AgentHostMonitoring {
         return diskGauge;
     }
 
+    public static Map<ArrayList<String>, Map<ArrayList<String>, Double>> 
getDiskIOGauge(JsonNode agentMonitoring) {
+        SystemInfo si = new SystemInfo();
+        BaseAgentGauge gaugeBaseInfo = new BaseAgentGauge(agentMonitoring);
+        ArrayList<String> diskIOGaugeLabels = gaugeBaseInfo.getLabels();
+        ArrayList<String> diskIOGaugeLabelsValues = 
gaugeBaseInfo.getLabelsValues();
+        diskIOGaugeLabels.add(AgentHostMonitoring.PHYSICAL_DISK_NAME);
+        diskIOGaugeLabels.add("diskIO");
+        Map<ArrayList<String>, Double> labelValues = new HashMap<>();
+
+        Util.sleep(1000);
+        List<HWDiskStore> upDiskStores = si.getHardware().getDiskStores();
+        long[] currentReadBytes = new long[upDiskStores.size()];
+        long[] currentWriteBytes = new long[upDiskStores.size()];
+
+        for (int i = 0; i < upDiskStores.size(); i++) {
+            HWDiskStore disk = upDiskStores.get(i);
+            currentReadBytes[i] = disk.getReadBytes();
+            currentWriteBytes[i] = disk.getWriteBytes();
+        }
+
+        for (int i = 0; i < upDiskStores.size(); i++) {
+            long readBytesDelta = Math.abs(currentReadBytes[i] - 
previousReadBytes[i]);
+            long writeBytesDelta = Math.abs(currentWriteBytes[i] - 
previousWriteBytes[i]);
+            double readKB = readBytesDelta / 1024.0;
+            double writeKB = writeBytesDelta / 1024.0; // kbs
+            previousReadBytes[i] = currentReadBytes[i];
+            previousWriteBytes[i] = currentWriteBytes[i];
+
+            // Disk Read
+            ArrayList<String> diskReadLabelValues = new 
ArrayList<>(diskIOGaugeLabelsValues);
+            diskReadLabelValues.add(upDiskStores.get(i).getName());
+            diskReadLabelValues.add(AgentHostMonitoring.DISK_READ);
+            labelValues.put(diskReadLabelValues, readKB);
+
+            // Disk Write
+            ArrayList<String> diskWriteLabelValues = new 
ArrayList<>(diskIOGaugeLabelsValues);
+            diskWriteLabelValues.add(upDiskStores.get(i).getName());
+            diskWriteLabelValues.add(AgentHostMonitoring.DISK_WRITE);
+            labelValues.put(diskWriteLabelValues, writeKB);
+        }
+
+        Map<ArrayList<String>, Map<ArrayList<String>, Double>> diskIOGauge = 
new HashMap<>();
+        diskIOGauge.put(diskIOGaugeLabels, labelValues);
+        return diskIOGauge;
+    }
+
     public static Map<ArrayList<String>, Map<ArrayList<String>, Double>> 
getCPUGauge(JsonNode agentMonitoring) {
 
         SystemInfo si = new SystemInfo();
@@ -299,6 +386,13 @@ public class AgentHostMonitoring {
                 .register(registry);
     }
 
+    public static MultiGauge newDiskIOMultiGauge(MeterRegistry registry) {
+        return MultiGauge.builder("agent_host_monitoring")
+                .description("BigTop Manager Agent Host Monitoring, DiskIO 
Monitoring")
+                .baseUnit("diskIO")
+                .register(registry);
+    }
+
     public static void multiGaugeUpdateData(
             MultiGauge multiGauge, Map<ArrayList<String>, 
Map<ArrayList<String>, Double>> gaugeData) {
         ArrayList<String> tagKeys = null;
@@ -351,4 +445,13 @@ public class AgentHostMonitoring {
             throw new RuntimeException("Get agent host monitoring info 
failed");
         }
     }
+
+    public static void diskIOMultiGaugeUpdateData(MultiGauge diskIOMultiGauge) 
{
+        try {
+            Map<ArrayList<String>, Map<ArrayList<String>, Double>> diskGauge = 
getDiskIOGauge(getHostInfo());
+            multiGaugeUpdateData(diskIOMultiGauge, diskGauge);
+        } catch (UnknownHostException e) {
+            throw new RuntimeException("Get agent host monitoring info 
failed");
+        }
+    }
 }
diff --git 
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/MonitoringController.java
 
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/MonitoringController.java
index 9ddd213..03ad663 100644
--- 
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/MonitoringController.java
+++ 
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/controller/MonitoringController.java
@@ -42,6 +42,19 @@ public class MonitoringController {
     @Operation(summary = "agent healthy", description = "agent healthy check")
     @GetMapping("agenthealthy")
     public ResponseEntity<JsonNode> agentHostsHealthyStatus() {
+        // json for response
         return 
ResponseEntity.success(monitoringService.queryAgentsHealthyStatus());
     }
+
+    @Operation(summary = "agent Info", description = "agent info query")
+    @GetMapping("agentinfo")
+    public ResponseEntity<JsonNode> queryAgentsInfo() {
+        return ResponseEntity.success(monitoringService.queryAgentsInfo());
+    }
+
+    @Operation(summary = "agent instant info", description = "agent instant 
info query")
+    @GetMapping("agentinstinfo")
+    public ResponseEntity<JsonNode> queryAgentsInstStatus() {
+        return 
ResponseEntity.success(monitoringService.queryAgentsInstStatus());
+    }
 }
diff --git 
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/proxy/PrometheusProxy.java
 
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/proxy/PrometheusProxy.java
index 4a18ea4..e57f44f 100644
--- 
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/proxy/PrometheusProxy.java
+++ 
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/proxy/PrometheusProxy.java
@@ -33,6 +33,9 @@ import reactor.core.publisher.Mono;
 import java.time.Instant;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
 
 @Component
 public class PrometheusProxy {
@@ -81,4 +84,250 @@ public class PrometheusProxy {
         }
         return agentsHealthyStatus;
     }
+
+    private JsonNode queryAgents() {
+        JsonNode result = query("agent_host_monitoring_cpu");
+        ObjectMapper objectMapper = new ObjectMapper();
+        if (result != null) {
+            JsonNode agentCpus = result.get("data").get("result");
+            if (agentCpus.isArray() && !agentCpus.isEmpty()) {
+                Set<String> iPv4addrSet = new HashSet<>();
+                for (JsonNode agent : agentCpus) {
+                    
iPv4addrSet.add(agent.get("metric").get("iPv4addr").asText());
+                }
+                ArrayNode iPv4addrArray = objectMapper.createArrayNode();
+                for (String value : iPv4addrSet.toArray(new String[0])) {
+                    iPv4addrArray.add(value);
+                }
+                return objectMapper.createObjectNode().set("iPv4addr", 
iPv4addrArray); // iPv4
+            }
+        }
+        return objectMapper.createObjectNode();
+    }
+
+    public JsonNode queryAgentsInfo() {
+        ObjectMapper objectMapper = new ObjectMapper();
+        ArrayNode agentsInfo = objectMapper.createArrayNode();
+        JsonNode agents = queryAgents().get("iPv4addr"); // get all host
+
+        for (JsonNode agent : agents) {
+            ObjectNode temp = objectMapper.createObjectNode();
+            JsonNode cpuResult = queryAgentCpu(agent.asText());
+            JsonNode memResult = queryAgentMemory(agent.asText());
+            JsonNode diskResult = queryAgentDisk(agent.asText());
+            // hostInfo
+            temp.put("hostname", cpuResult.get("hostname").asText());
+            temp.put("iPv4addr", cpuResult.get("iPv4addr").asText());
+            // temp.put("iPv6addr", cpuResult.get("iPv6addr").asText());
+            temp.put("cpuInfo", cpuResult.get("cpuInfo").asText().strip());
+            temp.put("time", cpuResult.get("time").asText());
+            temp.put("os", cpuResult.get("os").asText());
+            temp.put("architecture", cpuResult.get("architecture").asText());
+            temp.put("physical_cores", 
cpuResult.get("physical_cores").asText());
+            // MEM
+            temp.put("memIdle", memResult.get("memIdle").asLong());
+            temp.put("memTotal", memResult.get("memTotal").asLong());
+            // DISK
+            temp.set("diskSpace", diskResult.get("diskInfo"));
+            agentsInfo.add(temp);
+        }
+
+        return agentsInfo;
+    }
+
+    public JsonNode queryAgentsInstStatus() {
+        ObjectMapper objectMapper = new ObjectMapper();
+        ArrayNode agentsInfo = objectMapper.createArrayNode();
+        JsonNode agents = queryAgents().get("iPv4addr"); // get all host
+
+        for (JsonNode agent : agents) {
+            JsonNode cpuResult = queryAgentCpu(agent.asText());
+            JsonNode memResult = queryAgentMemory(agent.asText());
+            JsonNode diskResult = queryAgentDisk(agent.asText());
+            JsonNode diskIOResult = queryAgentDiskIO(agent.asText());
+            ObjectNode temp = objectMapper.createObjectNode();
+
+            // hostInfo
+            temp.put("hostname", cpuResult.get("hostname").asText());
+            temp.put("iPv4addr", cpuResult.get("iPv4addr").asText());
+            temp.put("cpuInfo", cpuResult.get("cpuInfo").asText().strip());
+            temp.put("time", cpuResult.get("time").asText());
+            temp.put("cpuLoadAvgMin_1", 
cpuResult.get("cpuLoadAvgMin_1").asDouble());
+            temp.put("cpuLoadAvgMin_5", 
cpuResult.get("cpuLoadAvgMin_5").asDouble());
+            temp.put("cpuLoadAvgMin_15", 
cpuResult.get("cpuLoadAvgMin_15").asDouble());
+            temp.put("cpuUsage", cpuResult.get("cpuUsage").asDouble());
+            temp.put("fileTotalDescriptor", 
cpuResult.get("fileTotalDescriptor").asLong());
+            temp.put("fileOpenDescriptor", 
cpuResult.get("fileOpenDescriptor").asLong());
+            // MEM
+            temp.put("memIdle", memResult.get("memIdle").asLong());
+            temp.put("memTotal", memResult.get("memTotal").asLong());
+            // DISK
+            temp.set("diskSpace", diskResult.get("diskInfo"));
+            // DISK IO
+            temp.set("diskIO", diskIOResult.get("diskIO"));
+            agentsInfo.add(temp);
+        }
+
+        return agentsInfo;
+    }
+
+    public JsonNode query(String params) {
+        Mono<JsonNode> body = webClient
+                .post()
+                .uri("/api/v1/query")
+                .contentType(MediaType.APPLICATION_FORM_URLENCODED)
+                .body(BodyInserters.fromFormData("query", 
params).with("timeout", "10"))
+                .retrieve()
+                .bodyToMono(JsonNode.class);
+        JsonNode result = body.block();
+        if (result == null
+                || result.isEmpty()
+                || !"success".equals(result.get("status").asText("failure"))) {
+            return null;
+        }
+        return result;
+    }
+
+    public JsonNode queryAgentCpu(String iPv4addr) {
+        String params = 
String.format("agent_host_monitoring_cpu{iPv4addr=\"%s\"}", iPv4addr);
+        JsonNode result = query(params);
+        ObjectMapper objectMapper = new ObjectMapper();
+        if (result != null) {
+            JsonNode agentCpus = result.get("data").get("result");
+            if (agentCpus.isArray() && !agentCpus.isEmpty()) {
+                JsonNode agentCpuMetric = agentCpus.get(0).get("metric");
+                JsonNode agentCpuValue = agentCpus.get(0).get("value");
+                ObjectNode agentInfo = objectMapper.createObjectNode();
+                agentInfo.put("hostname", 
agentCpuMetric.get("hostname").asText());
+                agentInfo.put("cpuInfo", 
agentCpuMetric.get("cpu_info").asText());
+                agentInfo.put("iPv4addr", 
agentCpuMetric.get("iPv4addr").asText());
+                // temp.put("iPv6addr", 
agentCpuMetric.get("iPv6addr").asText());
+                agentInfo.put("os", agentCpuMetric.get("os").asText());
+                agentInfo.put("architecture", 
agentCpuMetric.get("arch").asText());
+                agentInfo.put(
+                        "physical_cores", 
agentCpuMetric.get("physical_cores").asText());
+                agentInfo.put(
+                        "fileOpenDescriptor",
+                        agentCpuMetric.get("fileOpenDescriptor").asLong());
+                agentInfo.put(
+                        "fileTotalDescriptor",
+                        agentCpuMetric.get("fileTotalDescriptor").asLong());
+                LocalDateTime instant = Instant.ofEpochSecond(
+                                agentCpuValue.get(0).asLong())
+                        .atZone(ZoneId.systemDefault())
+                        .toLocalDateTime();
+                agentInfo.put("time", instant.toString());
+                for (JsonNode agent : agentCpus) {
+                    agentInfo.put(
+                            agent.get("metric").get("cpuUsage").asText(),
+                            agent.get("value").get(1).asDouble()); // cpu 
metric
+                }
+                return agentInfo;
+            }
+        }
+        return objectMapper.createObjectNode();
+    }
+
+    public JsonNode queryAgentMemory(String iPv4addr) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        String query = 
String.format("agent_host_monitoring_mem{iPv4addr=\"%s\"}", iPv4addr);
+        JsonNode result = query(query);
+        if (result != null) {
+            JsonNode agentsMem = result.get("data").get("result");
+            if (agentsMem.isArray() && !agentsMem.isEmpty()) {
+                JsonNode agentMemValue = agentsMem.get(0).get("value");
+                JsonNode agentMemMetric = agentsMem.get(0).get("metric");
+                ObjectNode agentsInfo = objectMapper.createObjectNode();
+                agentsInfo.put("hostname", 
agentMemMetric.get("hostname").asText());
+                agentsInfo.put("iPv4addr", 
agentMemMetric.get("iPv4addr").asText());
+                LocalDateTime instant = Instant.ofEpochSecond(
+                                agentMemValue.get(0).asLong())
+                        .atZone(ZoneId.systemDefault())
+                        .toLocalDateTime();
+                agentsInfo.put("time", instant.toString());
+                for (JsonNode agent : agentsMem) {
+                    agentsInfo.put(
+                            agent.get("metric").get("memUsage").asText(),
+                            agent.get("value").get(1).asLong()); // mem metric
+                }
+                return agentsInfo;
+            }
+        }
+        return objectMapper.createObjectNode();
+    }
+
+    public JsonNode queryAgentDisk(String iPv4addr) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        String params = 
String.format("agent_host_monitoring_disk{iPv4addr=\"%s\"}", iPv4addr);
+        JsonNode result = query(params);
+        if (result != null) {
+            JsonNode agentDisksResult = result.get("data").get("result");
+            if (agentDisksResult.isArray() && !agentDisksResult.isEmpty()) {
+                JsonNode agentDisksMetric = 
agentDisksResult.get(0).get("metric");
+                JsonNode agentDisksValue = 
agentDisksResult.get(0).get("value");
+                ObjectNode agentDiskInfo = objectMapper.createObjectNode();
+                agentDiskInfo.put("hostname", 
agentDisksMetric.get("hostname").asText());
+                agentDiskInfo.put("iPv4addr", 
agentDisksMetric.get("iPv4addr").asText());
+                LocalDateTime instant = Instant.ofEpochSecond(
+                                agentDisksValue.get(0).asLong())
+                        .atZone(ZoneId.systemDefault())
+                        .toLocalDateTime();
+                agentDiskInfo.put("time", instant.toString());
+
+                ArrayNode tempDiskInfo = objectMapper.createArrayNode();
+                for (JsonNode agent : agentDisksResult) {
+                    JsonNode agentDisk = agent.get("metric");
+                    ObjectNode temp = objectMapper.createObjectNode();
+                    temp.put("diskName", agentDisk.get("diskUsage").asText());
+                    temp.put("diskUsage", agentDisk.get("diskUsage").asText());
+                    temp.put("diskValue", agent.get("value").get(1).asLong());
+                    tempDiskInfo.add(temp);
+                }
+                agentDiskInfo.set("diskInfo", tempDiskInfo);
+                return agentDiskInfo;
+            }
+        }
+        return objectMapper.createObjectNode();
+    }
+
+    public JsonNode queryAgentDiskIO(String iPv4addr) {
+        ObjectMapper objectMapper = new ObjectMapper();
+        String params = 
String.format("agent_host_monitoring_diskIO{iPv4addr=\"%s\"}", iPv4addr);
+        JsonNode result = query(params);
+        if (result != null) {
+            JsonNode agentDisksResult = result.get("data").get("result");
+            if (agentDisksResult.isArray() && !agentDisksResult.isEmpty()) {
+                JsonNode agentDisksValue = 
agentDisksResult.get(0).get("value");
+                JsonNode agentDisksMetric = 
agentDisksResult.get(0).get("metric");
+                ObjectNode agentDiskIOInfo = objectMapper.createObjectNode();
+                agentDiskIOInfo
+                        .put("hostname", 
agentDisksMetric.get("hostname").asText())
+                        .put("iPv4addr", 
agentDisksMetric.get("iPv4addr").asText());
+                LocalDateTime instant = Instant.ofEpochSecond(
+                                agentDisksValue.get(0).asLong())
+                        .atZone(ZoneId.systemDefault())
+                        .toLocalDateTime();
+                agentDiskIOInfo.put("time", instant.toString());
+
+                ArrayNode tempDiskInfo = objectMapper.createArrayNode();
+                for (JsonNode agent : agentDisksResult) {
+                    JsonNode agentDisk = agent.get("metric");
+                    ObjectNode temp = objectMapper.createObjectNode();
+                    temp.put(
+                            "physicalDiskName",
+                            agentDisk.get("physicalDiskName").asText());
+                    temp.put("physicalDiskUsage", 
agentDisk.get("diskIO").asText());
+                    if (Objects.equals(agentDisk.get("diskIO").asText(), 
"physicalDiskWrite")) {
+                        temp.put("physicalDiskWrite", 
agent.get("value").get(1).asLong());
+                    } else {
+                        temp.put("physicalDiskRead", 
agent.get("value").get(1).asLong());
+                    }
+                    tempDiskInfo.add(temp);
+                }
+                agentDiskIOInfo.set("diskIO", tempDiskInfo);
+                return agentDiskIOInfo;
+            }
+        }
+        return objectMapper.createObjectNode();
+    }
 }
diff --git 
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/MonitoringService.java
 
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/MonitoringService.java
index 3aaea1d..ce6f82d 100644
--- 
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/MonitoringService.java
+++ 
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/MonitoringService.java
@@ -23,4 +23,8 @@ import com.fasterxml.jackson.databind.JsonNode;
 public interface MonitoringService {
 
     JsonNode queryAgentsHealthyStatus();
+
+    JsonNode queryAgentsInfo();
+
+    JsonNode queryAgentsInstStatus();
 }
diff --git 
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/MonitoringServiceImpl.java
 
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/MonitoringServiceImpl.java
index f846c5f..38dde15 100644
--- 
a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/MonitoringServiceImpl.java
+++ 
b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/MonitoringServiceImpl.java
@@ -39,4 +39,14 @@ public class MonitoringServiceImpl implements 
MonitoringService {
     public JsonNode queryAgentsHealthyStatus() {
         return prometheusProxy.queryAgentsHealthyStatus();
     }
+
+    @Override
+    public JsonNode queryAgentsInfo() {
+        return prometheusProxy.queryAgentsInfo();
+    }
+
+    @Override
+    public JsonNode queryAgentsInstStatus() {
+        return prometheusProxy.queryAgentsInstStatus();
+    }
 }

Reply via email to