in bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/proxy/PrometheusProxy.java [212:273]
public JsonNode queryClustersInfo(List<String> agentIpv4s, String interval) {
int agentsNum = agentIpv4s.size(); // change to agentsNum
ObjectMapper objectMapper = new ObjectMapper();
if (agentsNum > 0) {
int totalPhysicalCores = 0;
long totalMemSpace = 0L, totalMemIdle = 0L;
double instantCpuUsage = 0.0;
double[][] agentsCpuUsage = new double[agentsNum][6];
double[][] agentsCpuLoad1 = new double[agentsNum][6];
double[][] agentsCpuLoad2 = new double[agentsNum][6];
double[][] agentsCpuLoad3 = new double[agentsNum][6];
long[][] agentMemIdle = new long[agentsNum][6];
long[][] agentMemTotal = new long[agentsNum][6];
int agentIndex = 0;
ObjectNode clusterInfo = objectMapper.createObjectNode();
for (String agentIpv4 : agentIpv4s) {
JsonNode agentCpu = retrieveAgentCpu(agentIpv4);
instantCpuUsage += agentCpu.get("cpuUsage").asDouble()
* agentCpu.get(PHYSICAL_CORES).asInt();
JsonNode agentMem = retrieveAgentMemory(agentIpv4);
totalMemIdle += agentMem.get("memIdle").asLong();
totalMemSpace += agentMem.get(("memTotal")).asLong();
JsonNode agentCpuStep = retrieveAgentCpu(agentIpv4, interval);
JsonNode agentMemStep = retrieveAgentMemory(agentIpv4, interval);
int agentPhysicalCores = agentCpu.get(PHYSICAL_CORES).asInt();
totalPhysicalCores += agentPhysicalCores;
for (int i = 0; i < 6; i++) {
// CPU
agentsCpuUsage[agentIndex][i] =
ProxyUtils.getDoubleSafely(agentCpuStep, CPU_USAGE, i) * agentPhysicalCores;
agentsCpuLoad1[agentIndex][i] =
ProxyUtils.getDoubleSafely(agentCpuStep, CPU_LOAD_AVG_MIN_1, i) * agentPhysicalCores;
agentsCpuLoad2[agentIndex][i] =
ProxyUtils.getDoubleSafely(agentCpuStep, CPU_LOAD_AVG_MIN_5, i) * agentPhysicalCores;
agentsCpuLoad3[agentIndex][i] =
ProxyUtils.getDoubleSafely(agentCpuStep, CPU_LOAD_AVG_MIN_15, i) * agentPhysicalCores;
// MEM
agentMemIdle[agentIndex][i] = ProxyUtils.getLongSafely(agentMemStep, MEM_IDLE, i);
agentMemTotal[agentIndex][i] = ProxyUtils.getLongSafely(agentMemStep, MEM_TOTAL, i);
}
agentIndex++; // loop of agents
}
// cur
clusterInfo.put("cpuUsageCur", String.format("%.6f", instantCpuUsage / totalPhysicalCores));
clusterInfo.put(
"memoryUsageCur", String.format("%.6f", (double) (totalMemSpace - totalMemIdle) / totalMemSpace));
// interval
clusterInfo.set("cpuUsage", ProxyUtils.array2node(agentsCpuUsage, totalPhysicalCores, agentsNum));
clusterInfo.set("systemLoad1", ProxyUtils.array2node(agentsCpuLoad1, totalPhysicalCores, agentsNum));
clusterInfo.set("systemLoad2", ProxyUtils.array2node(agentsCpuLoad2, totalPhysicalCores, agentsNum));
clusterInfo.set("systemLoad3", ProxyUtils.array2node(agentsCpuLoad3, totalPhysicalCores, agentsNum));
clusterInfo.set("memoryUsage", ProxyUtils.array2node(agentMemIdle, agentMemTotal, agentsNum));
return clusterInfo;
}
return objectMapper.createObjectNode();
}