refactor(性能测试): 优化性能测试中对于资源池的监控
This commit is contained in:
parent
de4a5de968
commit
e477be9c1b
|
@ -1,14 +1,20 @@
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<span :class="labelClassName" :title="nodeName" >{{nodeName}}</span>
|
<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">
|
<el-tag v-if="nodeOperationInfo!== undefined && nodeOperationInfo.runningTask>0" size="mini"
|
||||||
{{$t("commons.running")}}</el-tag>
|
style="color:#E5594B;background-color: #FFFFFF;border-color: #E5594B;margin-left: 5px;margin-right: 5px">
|
||||||
<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.running") }}
|
||||||
{{$t("commons.idle")}}</el-tag>
|
</el-tag>
|
||||||
<span v-if="nodeOperationInfo!== undefined && nodeOperationInfo.runningTask>0" style="color:#A9A9A9">
|
<el-tag v-else-if="nodeOperationInfo!== undefined" size="mini"
|
||||||
{{" CPU:"+nodeOperationInfo.cpuUsage}}</span>
|
style="color:#89DB7E;background-color: #FFFFFF;border-color: #89DB7E;margin-left: 5px;margin-right: 5px">
|
||||||
<span v-if="nodeOperationInfo!== undefined " style="color:#A9A9A9;">
|
{{ $t("commons.idle") }}
|
||||||
{{" CPU:"+nodeOperationInfo.cpuUsage}}</span>
|
</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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -17,7 +23,7 @@ export default {
|
||||||
name: "NodeOperationLabel",
|
name: "NodeOperationLabel",
|
||||||
props: {
|
props: {
|
||||||
nodeName: String,
|
nodeName: String,
|
||||||
nodeOperationInfo:Object,
|
nodeOperationInfo: Object,
|
||||||
labelClassName: {
|
labelClassName: {
|
||||||
type: String,
|
type: String,
|
||||||
default: "node-label"
|
default: "node-label"
|
||||||
|
@ -29,19 +35,17 @@ export default {
|
||||||
defaultInitOptions: this.initOptions
|
defaultInitOptions: this.initOptions
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {},
|
||||||
},
|
|
||||||
mounted() {
|
mounted() {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.node-label{
|
.node-label {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
width:240px;
|
width: 240px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
|
|
@ -8,15 +8,17 @@ import java.util.Map;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ResourcePoolOperationInfo {
|
public class ResourcePoolOperationInfo {
|
||||||
|
Map<String, NodeOperationInfo> nodeOperationInfos = new HashMap<>();
|
||||||
private String id;
|
private String id;
|
||||||
private String cpuUsage;
|
private String cpuUsage;
|
||||||
private int runningTask = 0;
|
private int runningTask = 0;
|
||||||
Map<String, NodeOperationInfo> nodeOperationInfos = new HashMap<>();
|
|
||||||
|
|
||||||
public void addNodeOperationInfo(String taskResourceId, String ip, String port, String cpuUsage, int runningTask) {
|
public void addNodeOperationInfo(String taskResourceId, String ip, String port, String cpuUsage, int runningTask) {
|
||||||
if(StringUtils.isBlank(cpuUsage)) {
|
if (StringUtils.isBlank(cpuUsage) && runningTask < 0) {
|
||||||
//节点下如果获取不到cpu使用率,判断为没有查询到该节点的数据。
|
//节点下如果获取不到cpu使用率,且没有查到runningTask数据,判断为没有查询到该节点的数据。
|
||||||
return;
|
return;
|
||||||
|
} else if (StringUtils.isBlank(cpuUsage)) {
|
||||||
|
cpuUsage = "NONE";
|
||||||
}
|
}
|
||||||
NodeOperationInfo nodeOperationInfo = new NodeOperationInfo();
|
NodeOperationInfo nodeOperationInfo = new NodeOperationInfo();
|
||||||
nodeOperationInfo.setIp(ip);
|
nodeOperationInfo.setIp(ip);
|
||||||
|
@ -30,7 +32,7 @@ public class ResourcePoolOperationInfo {
|
||||||
|
|
||||||
if (nodeOperationInfos.size() > 1) {
|
if (nodeOperationInfos.size() > 1) {
|
||||||
//多节点的情况下暂不处理CPU使用率
|
//多节点的情况下暂不处理CPU使用率
|
||||||
this.cpuUsage = null;
|
this.cpuUsage = "NONE";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,29 +78,25 @@ public class PrometheusService {
|
||||||
ResourcePoolOperationInfo nodeOperationInfo = new ResourcePoolOperationInfo();
|
ResourcePoolOperationInfo nodeOperationInfo = new ResourcePoolOperationInfo();
|
||||||
nodeOperationInfo.setId(testResourcePoolDTO.getId());
|
nodeOperationInfo.setId(testResourcePoolDTO.getId());
|
||||||
|
|
||||||
boolean queryCpuUsage = true;
|
//如果没有在prometheus查到数据则runningTask为-1。
|
||||||
if (testResourcePoolDTO.getResources().size() > 1) {
|
|
||||||
queryCpuUsage = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
String cpuUsage = null;
|
|
||||||
int runningTask = -1;
|
int runningTask = -1;
|
||||||
|
|
||||||
for (TestResource testResource : testResourcePoolDTO.getResources()) {
|
for (TestResource testResource : testResourcePoolDTO.getResources()) {
|
||||||
String config = testResource.getConfiguration();
|
String config = testResource.getConfiguration();
|
||||||
|
try {
|
||||||
|
//防止出现没有更新的node-controller引起报错,从而影响整个系统
|
||||||
if (StringUtils.isNotBlank(config)) {
|
if (StringUtils.isNotBlank(config)) {
|
||||||
|
String cpuUsage = null;
|
||||||
Map<String, Object> configMap = JSON.parseObject(config, Map.class);
|
Map<String, Object> configMap = JSON.parseObject(config, Map.class);
|
||||||
String ip = String.valueOf(configMap.get("ip"));
|
String ip = String.valueOf(configMap.get("ip"));
|
||||||
String port = String.valueOf(configMap.get("port"));
|
String port = String.valueOf(configMap.get("port"));
|
||||||
String nodeId = ip + ":" + port;
|
String nodeId = ip + ":" + port;
|
||||||
if (queryCpuUsage) {
|
|
||||||
String cpuUsageQL = this.generatePromQL(new String[]{"system_cpu_usage"}, nodeId);
|
String cpuUsageQL = this.generatePromQL(new String[]{"system_cpu_usage"}, nodeId);
|
||||||
LogUtil.debug(host + "/api/v1/query?query=" + cpuUsageQL);
|
LogUtil.debug(host + "/api/v1/query?query=" + cpuUsageQL);
|
||||||
String cpuUsageDouble = this.runPromQL(headers, host, cpuUsageQL);
|
String cpuUsageDouble = this.runPromQL(headers, host, cpuUsageQL);
|
||||||
if(StringUtils.isNotBlank(cpuUsageDouble)){
|
if (StringUtils.isNotBlank(cpuUsageDouble)) {
|
||||||
cpuUsage = decimalFormat.format(Double.parseDouble(cpuUsageDouble) * 100) + "%";
|
cpuUsage = decimalFormat.format(Double.parseDouble(cpuUsageDouble) * 100) + "%";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 查询任务数
|
// 查询任务数
|
||||||
List<String> taskSeriesNames = new ArrayList<>() {{
|
List<String> taskSeriesNames = new ArrayList<>() {{
|
||||||
|
@ -110,10 +106,16 @@ public class PrometheusService {
|
||||||
String taskCountQL = this.generatePromQL(taskSeriesNames.toArray(new String[0]), nodeId);
|
String taskCountQL = this.generatePromQL(taskSeriesNames.toArray(new String[0]), nodeId);
|
||||||
String result = this.runPromQL(headers, host, taskCountQL);
|
String result = this.runPromQL(headers, host, taskCountQL);
|
||||||
if (StringUtils.isNotBlank(result)) {
|
if (StringUtils.isNotBlank(result)) {
|
||||||
|
if (runningTask == -1) {
|
||||||
|
runningTask = 0;
|
||||||
|
}
|
||||||
runningTask += Integer.parseInt(result);
|
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())) {
|
if (MapUtils.isNotEmpty(nodeOperationInfo.getNodeOperationInfos())) {
|
||||||
returnList.add(nodeOperationInfo);
|
returnList.add(nodeOperationInfo);
|
||||||
|
|
Loading…
Reference in New Issue