refactor(性能测试): 优化性能测试中对于资源池的监控

This commit is contained in:
song-tianyang 2023-10-13 17:43:08 +08:00 committed by 刘瑞斌
parent de4a5de968
commit e477be9c1b
3 changed files with 52 additions and 44 deletions

View File

@ -1,14 +1,20 @@
<template>
<div>
<span :class="labelClassName" :title="nodeName" >{{nodeName}}</span>
<el-tag size="mini" v-if="nodeOperationInfo!== undefined && nodeOperationInfo.runningTask>0" style="color:#E5594B;background-color: #FFFFFF;border-color: #E5594B;margin-left: 5px;margin-right: 5px">
{{$t("commons.running")}}</el-tag>
<el-tag size="mini" v-else-if="nodeOperationInfo!== undefined" style="color:#89DB7E;background-color: #FFFFFF;border-color: #89DB7E;margin-left: 5px;margin-right: 5px">
{{$t("commons.idle")}}</el-tag>
<span v-if="nodeOperationInfo!== undefined && nodeOperationInfo.runningTask>0" style="color:#A9A9A9">
{{" CPU:"+nodeOperationInfo.cpuUsage}}</span>
<span v-if="nodeOperationInfo!== undefined " style="color:#A9A9A9;">
{{" CPU:"+nodeOperationInfo.cpuUsage}}</span>
<span :class="labelClassName" :title="nodeName">{{ nodeName }}</span>
<el-tag v-if="nodeOperationInfo!== undefined && nodeOperationInfo.runningTask>0" size="mini"
style="color:#E5594B;background-color: #FFFFFF;border-color: #E5594B;margin-left: 5px;margin-right: 5px">
{{ $t("commons.running") }}
</el-tag>
<el-tag v-else-if="nodeOperationInfo!== undefined" size="mini"
style="color:#89DB7E;background-color: #FFFFFF;border-color: #89DB7E;margin-left: 5px;margin-right: 5px">
{{ $t("commons.idle") }}
</el-tag>
<span
v-if="nodeOperationInfo!== undefined && nodeOperationInfo.runningTask>0 && nodeOperationInfo.cpuUsage!== undefined"
style="color:#A9A9A9">
{{ " CPU:" + nodeOperationInfo.cpuUsage }}</span>
<span v-if="nodeOperationInfo!== undefined && nodeOperationInfo.cpuUsage!== undefined" style="color:#A9A9A9;">
{{ " CPU:" + nodeOperationInfo.cpuUsage }}</span>
</div>
</template>
@ -17,7 +23,7 @@ export default {
name: "NodeOperationLabel",
props: {
nodeName: String,
nodeOperationInfo:Object,
nodeOperationInfo: Object,
labelClassName: {
type: String,
default: "node-label"
@ -29,19 +35,17 @@ export default {
defaultInitOptions: this.initOptions
};
},
computed: {
},
computed: {},
mounted() {
},
methods: {
}
methods: {}
};
</script>
<style scoped>
.node-label{
.node-label {
display: inline-flex;
width:240px;
width: 240px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;

View File

@ -8,15 +8,17 @@ import java.util.Map;
@Data
public class ResourcePoolOperationInfo {
Map<String, NodeOperationInfo> nodeOperationInfos = new HashMap<>();
private String id;
private String cpuUsage;
private int runningTask = 0;
Map<String, NodeOperationInfo> nodeOperationInfos = new HashMap<>();
public void addNodeOperationInfo(String taskResourceId, String ip, String port, String cpuUsage, int runningTask) {
if(StringUtils.isBlank(cpuUsage)) {
//节点下如果获取不到cpu使用率判断为没有查询到该节点的数据
if (StringUtils.isBlank(cpuUsage) && runningTask < 0) {
//节点下如果获取不到cpu使用率且没有查到runningTask数据判断为没有查询到该节点的数据
return;
} else if (StringUtils.isBlank(cpuUsage)) {
cpuUsage = "NONE";
}
NodeOperationInfo nodeOperationInfo = new NodeOperationInfo();
nodeOperationInfo.setIp(ip);
@ -30,7 +32,7 @@ public class ResourcePoolOperationInfo {
if (nodeOperationInfos.size() > 1) {
//多节点的情况下暂不处理CPU使用率
this.cpuUsage = null;
this.cpuUsage = "NONE";
}
}
}

View File

@ -78,41 +78,43 @@ public class PrometheusService {
ResourcePoolOperationInfo nodeOperationInfo = new ResourcePoolOperationInfo();
nodeOperationInfo.setId(testResourcePoolDTO.getId());
boolean queryCpuUsage = true;
if (testResourcePoolDTO.getResources().size() > 1) {
queryCpuUsage = false;
}
String cpuUsage = null;
//如果没有在prometheus查到数据则runningTask为-1
int runningTask = -1;
for (TestResource testResource : testResourcePoolDTO.getResources()) {
String config = testResource.getConfiguration();
if (StringUtils.isNotBlank(config)) {
Map<String, Object> configMap = JSON.parseObject(config, Map.class);
String ip = String.valueOf(configMap.get("ip"));
String port = String.valueOf(configMap.get("port"));
String nodeId = ip + ":" + port;
if (queryCpuUsage) {
try {
//防止出现没有更新的node-controller引起报错从而影响整个系统
if (StringUtils.isNotBlank(config)) {
String cpuUsage = null;
Map<String, Object> configMap = JSON.parseObject(config, Map.class);
String ip = String.valueOf(configMap.get("ip"));
String port = String.valueOf(configMap.get("port"));
String nodeId = ip + ":" + port;
String cpuUsageQL = this.generatePromQL(new String[]{"system_cpu_usage"}, nodeId);
LogUtil.debug(host + "/api/v1/query?query=" + cpuUsageQL);
String cpuUsageDouble = this.runPromQL(headers, host, cpuUsageQL);
if(StringUtils.isNotBlank(cpuUsageDouble)){
if (StringUtils.isNotBlank(cpuUsageDouble)) {
cpuUsage = decimalFormat.format(Double.parseDouble(cpuUsageDouble) * 100) + "%";
}
}
// 查询任务数
List<String> taskSeriesNames = new ArrayList<>() {{
this.add("running_tasks_load_count");
this.add("running_tasks_api_count");
}};
String taskCountQL = this.generatePromQL(taskSeriesNames.toArray(new String[0]), nodeId);
String result = this.runPromQL(headers, host, taskCountQL);
if (StringUtils.isNotBlank(result)) {
runningTask += Integer.parseInt(result);
// 查询任务数
List<String> taskSeriesNames = new ArrayList<>() {{
this.add("running_tasks_load_count");
this.add("running_tasks_api_count");
}};
String taskCountQL = this.generatePromQL(taskSeriesNames.toArray(new String[0]), nodeId);
String result = this.runPromQL(headers, host, taskCountQL);
if (StringUtils.isNotBlank(result)) {
if (runningTask == -1) {
runningTask = 0;
}
runningTask += Integer.parseInt(result);
}
nodeOperationInfo.addNodeOperationInfo(String.valueOf(configMap.get("id")), ip, port, cpuUsage, runningTask);
}
nodeOperationInfo.addNodeOperationInfo(String.valueOf(configMap.get("id")), ip, port, cpuUsage, runningTask);
} catch (Exception e) {
LogUtil.error("查找node监控报错:" + testResourcePoolDTO.getName(), e);
}
}
if (MapUtils.isNotEmpty(nodeOperationInfo.getNodeOperationInfos())) {