Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BIGTOP-4296: Add API for cluster and host metrics #119

Merged
merged 34 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b208528
(perf):增加注释,方便理解
Cat-Drink Oct 6, 2024
69b016a
(feat):新增了queryAgentsInstStatus 和 queryAgentsInfo 的功能补充
Cat-Drink Oct 6, 2024
a56c453
(fix):修复普罗米修斯agentinfo和agentinstinfo请求query异常问题
Cat-Drink Oct 8, 2024
3c84790
(feat):bigtop_manager_agent新增 获取磁盘IO速率kbs提交至prometheus
Cat-Drink Oct 9, 2024
53f2168
(feat):bigtop_manager_agent新增 获取文件句柄使用率%提交至prometheus
Cat-Drink Oct 9, 2024
5c641e2
(fix):bigtop_manager_agent 优化架构和操作系统类型区分,修改文件句柄的获取方法
Cat-Drink Oct 9, 2024
5b34d3f
(update):bigtop_manager_server 更新接口返回:新增文件句柄获取,cpuInfo(CPU架构类型获取),分类接口
Cat-Drink Oct 9, 2024
574eeb5
(update):bigtop_manager_server 更新接口返回:新增DiskIO
Cat-Drink Oct 9, 2024
e3132b7
(docs):remove chinese comment
Cat-Drink Oct 12, 2024
3f28d58
(docs):remove chinese comment
Cat-Drink Oct 13, 2024
fb0fba3
(fix):withdraw this modification of application.yml
Cat-Drink Oct 13, 2024
4845692
(docs): change the chinese comment
Cat-Drink Oct 14, 2024
20781b4
(check):run spotless:apply
Cat-Drink Oct 15, 2024
4853770
(update):change separated DiskSpace metric
Cat-Drink Oct 19, 2024
5ed3761
Merge branch 'main' of https://github.com/Cat-Drink/bigtop-manager in…
Cat-Drink Nov 9, 2024
c9f8b68
(update): change cron
Cat-Drink Nov 9, 2024
d818a04
add some feature
Cat-Drink Nov 27, 2024
117a136
Merge branch 'main' of https://github.com/Cat-Drink/bigtop-manager in…
Cat-Drink Nov 27, 2024
1eceeaf
create BigtopProxy.java to get cluster host list
Cat-Drink Nov 28, 2024
6e2d8ca
get cluster by clusterId
Cat-Drink Nov 28, 2024
a5e0e5e
get agents Info and cluster info service
Cat-Drink Dec 7, 2024
c747e45
monitoring controller
Cat-Drink Dec 7, 2024
f0fcab4
proxy cluster and agents
Cat-Drink Dec 7, 2024
3aa4403
spotless check
Cat-Drink Dec 7, 2024
e54fa2e
add license head
Cat-Drink Dec 7, 2024
d1bd385
fix BigtopProxy.java
Cat-Drink Dec 8, 2024
8858d88
change param name and add some bound
Cat-Drink Dec 8, 2024
5e38c1a
fix chinese
Cat-Drink Dec 9, 2024
a9e4fe1
fix hard code
Cat-Drink Dec 9, 2024
6a13cf0
fix retrieve data api and data model
Cat-Drink Dec 25, 2024
ce694a3
update proxy metric service
Cat-Drink Dec 26, 2024
58f937f
fix coding style
Cat-Drink Dec 26, 2024
d157933
add comment
Cat-Drink Dec 26, 2024
7bf2bad
fix method params error and api
Cat-Drink Dec 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class MetricsCollector {
@Qualifier("diskIOMultiGauge") private MultiGauge diskIOMultiGauge;

@Async
@Scheduled(cron = "*/10 * * * * ?")
@Scheduled(cron = "0,30 * * * * ?")
public void collect() {
// refresh agent host monitoring data
scrape();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -42,19 +43,26 @@ 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")
@Operation(summary = "staticAgentInfo", description = "agent static info query")
@GetMapping("staticAgentInfo")
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());
@Operation(summary = "dynamicAgentInfo", description = "agent dynamic info query")
@GetMapping("dynamicAgentInfo")
public ResponseEntity<JsonNode> queryAgentsInfo(@RequestParam(value = "step", defaultValue = "1") String step) {
return ResponseEntity.success(monitoringService.queryAgentsInfo(step));
}

@Operation(summary = "cluster info", description = "cluster multi info")
@GetMapping("clusterInfo")
public ResponseEntity<JsonNode> queryCluster(
@RequestParam(value = "clusterId") String clusterId,
@RequestParam(value = "step", defaultValue = "1") String step) {
return ResponseEntity.success(monitoringService.queryClusterInfo(clusterId, step));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bigtop.manager.server.proxy;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import reactor.core.publisher.Mono;

@Component
public class BigtopProxy {

private final WebClient webClient;

public BigtopProxy(WebClient.Builder webClientBuilder, @Value("http://localhost:5173") String bigTopHost) {
this.webClient = webClientBuilder.baseUrl(bigTopHost).build();
}

private MultiValueMap<String, String> createFormData(Integer pageNum) {
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
formData.add("pageNum", String.valueOf(pageNum));
formData.add("pageSize", "20");
formData.add("orderBy", "id");
formData.add("sort", "asc");
return formData;
}

public JsonNode queryHosts(int pageNum) {
Mono<JsonNode> body = webClient
.post()
.uri(uriBuilder -> uriBuilder.path("/api/hosts").build())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.body(BodyInserters.fromFormData(createFormData(pageNum)))
.retrieve()
.bodyToMono(JsonNode.class);
JsonNode result = body.block();
if (result == null || result.isEmpty() || !(result.get("failed").asBoolean())) {
return null;
}
return result;
}

public JsonNode queryClusterAgents(String clusterId) {
ObjectMapper objectMapper = new ObjectMapper();
// query cluster name
Mono<JsonNode> body =
webClient.get().uri("/api/clusters/{id}", clusterId).retrieve().bodyToMono(JsonNode.class);
JsonNode result = body.block();
if (result == null || result.isEmpty() || !(result.get("failed").asBoolean())) return null;
String clusterName = result.get("data").get("name").asText();
ObjectNode clusterAgents = objectMapper.createObjectNode();
ArrayNode arrayNode = objectMapper.createArrayNode();
int pageNum = 1;
while (true) {
JsonNode agentsPage = queryHosts(pageNum++);
if (agentsPage == null) break;
JsonNode agentsContent = agentsPage.get("data").get("content");
agentsContent.forEach(agent -> {
if (agent.get("clusterName").asText().equals(clusterName))
arrayNode.add(agent.get("ipv4").asText());
});
}
clusterAgents.put("agentsNum", arrayNode.size());
clusterAgents.set("agents", arrayNode);
return clusterAgents;
}
}
Loading
Loading