diff --git a/backend/src/main/java/io/metersphere/controller/ShareController.java b/backend/src/main/java/io/metersphere/controller/ShareController.java index 9b9b173bd7..cb7de712cc 100644 --- a/backend/src/main/java/io/metersphere/controller/ShareController.java +++ b/backend/src/main/java/io/metersphere/controller/ShareController.java @@ -18,6 +18,7 @@ import io.metersphere.dto.LogDetailDTO; import io.metersphere.performance.base.*; import io.metersphere.performance.dto.LoadTestExportJmx; import io.metersphere.performance.dto.MetricData; +import io.metersphere.performance.dto.Monitor; import io.metersphere.performance.service.MetricQueryService; import io.metersphere.performance.service.PerformanceReportService; import io.metersphere.performance.service.PerformanceTestService; @@ -239,7 +240,7 @@ public class ShareController { } @GetMapping("/metric/query/resource/{shareId}/{id}") - public List queryReportResource(@PathVariable String shareId, @PathVariable("id") String reportId) { + public List queryReportResource(@PathVariable String shareId, @PathVariable("id") String reportId) { return metricService.queryReportResource(reportId); } diff --git a/backend/src/main/java/io/metersphere/performance/controller/MetricQueryController.java b/backend/src/main/java/io/metersphere/performance/controller/MetricQueryController.java index 5f65a57900..3865dd7840 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/MetricQueryController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/MetricQueryController.java @@ -1,6 +1,7 @@ package io.metersphere.performance.controller; import io.metersphere.performance.dto.MetricData; +import io.metersphere.performance.dto.Monitor; import io.metersphere.performance.service.MetricQueryService; import org.springframework.web.bind.annotation.*; @@ -20,7 +21,7 @@ public class MetricQueryController { } @GetMapping("/query/resource/{id}") - public List queryReportResource(@PathVariable("id") String reportId) { + public List queryReportResource(@PathVariable("id") String reportId) { return metricService.queryReportResource(reportId); } } diff --git a/backend/src/main/java/io/metersphere/performance/dto/Monitor.java b/backend/src/main/java/io/metersphere/performance/dto/Monitor.java index 81e3e8d3fa..de9e4cd016 100644 --- a/backend/src/main/java/io/metersphere/performance/dto/Monitor.java +++ b/backend/src/main/java/io/metersphere/performance/dto/Monitor.java @@ -3,14 +3,14 @@ package io.metersphere.performance.dto; import lombok.Getter; import lombok.Setter; +import java.util.List; + @Getter @Setter public class Monitor { private String name; - private String environmentId; - private String environmentName; private String ip; private Integer port; private String description; - private String monitorStatus; + private List monitorConfig; } diff --git a/backend/src/main/java/io/metersphere/performance/dto/MonitorItem.java b/backend/src/main/java/io/metersphere/performance/dto/MonitorItem.java new file mode 100644 index 0000000000..011faf83a4 --- /dev/null +++ b/backend/src/main/java/io/metersphere/performance/dto/MonitorItem.java @@ -0,0 +1,11 @@ +package io.metersphere.performance.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class MonitorItem { + private String value; // 表达式 + private String name; // 监控项 +} diff --git a/backend/src/main/java/io/metersphere/performance/service/MetricQueryService.java b/backend/src/main/java/io/metersphere/performance/service/MetricQueryService.java index fc203316ad..42205729d8 100644 --- a/backend/src/main/java/io/metersphere/performance/service/MetricQueryService.java +++ b/backend/src/main/java/io/metersphere/performance/service/MetricQueryService.java @@ -4,7 +4,6 @@ package io.metersphere.performance.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.alibaba.nacos.client.utils.StringUtils; import io.metersphere.base.domain.LoadTestReportWithBLOBs; import io.metersphere.base.domain.TestResource; import io.metersphere.base.mapper.LoadTestReportMapper; @@ -21,9 +20,11 @@ import io.metersphere.performance.controller.request.MetricQuery; import io.metersphere.performance.controller.request.MetricRequest; import io.metersphere.performance.dto.MetricData; import io.metersphere.performance.dto.Monitor; +import io.metersphere.performance.dto.MonitorItem; import io.metersphere.service.SystemParameterService; import io.metersphere.service.TestResourceService; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; @@ -156,7 +157,7 @@ public class MetricQueryService { } public List queryMetric(String reportId) { - List instances = new ArrayList<>(); + List instances = new ArrayList<>(); LoadTestReportWithBLOBs report = loadTestReportMapper.selectByPrimaryKey(reportId); String poolId = report.getTestResourcePoolId(); List resourceList = testResourceService.getTestResourceList(poolId); @@ -166,7 +167,10 @@ public class MetricQueryService { NodeDTO dto = JSON.parseObject(resource.getConfiguration(), NodeDTO.class); if (StringUtils.isNotBlank(dto.getIp())) { int port = dto.getMonitorPort() == null ? 9100 : dto.getMonitorPort(); - instances.add(dto.getIp() + ":" + port); + Monitor e = new Monitor(); + e.setIp(dto.getIp()); + e.setPort(port); + instances.add(e); } }); } @@ -179,11 +183,14 @@ public class MetricQueryService { List list = new ArrayList<>(); // 加入高级设置中的监控配置 for (int i = 0; i < monitorParams.size(); i++) { - Monitor monitor = monitorParams.getObject(i, Monitor.class); - String instance = monitor.getIp() + ":" + monitor.getPort(); - if (!instances.contains(instance)) { - instances.add(instance); - } + JSONObject o = monitorParams.getJSONObject(i); + Monitor monitor = new Monitor(); + monitor.setIp(o.getString("ip")); + monitor.setName(o.getString("name")); + monitor.setPort(o.getInteger("port")); + monitor.setDescription(o.getString("description")); + monitor.setMonitorConfig(JSONObject.parseArray(o.getString("monitorConfig"), MonitorItem.class)); + instances.add(monitor); } instances.forEach(instance -> { @@ -203,38 +210,55 @@ public class MetricQueryService { return queryMetricData(metricRequest); } - private void getRequest(String instance, List list) { - Map map = MetricQuery.getMetricQueryMap(); - Set set = map.keySet(); - set.forEach(s -> { - MetricDataRequest request = new MetricDataRequest(); - String promQL = map.get(s); - request.setPromQL(promQL); - request.setSeriesName(s); - request.setInstance(instance); - list.add(request); - }); + private void getRequest(Monitor monitor, List list) { + if (CollectionUtils.isNotEmpty(monitor.getMonitorConfig())) { + monitor.getMonitorConfig().forEach(c -> { + if (StringUtils.isBlank(c.getValue())) { + return; + } + MetricDataRequest request = new MetricDataRequest(); + String promQL = c.getValue(); + request.setPromQL(promQL); + request.setSeriesName(c.getName()); + request.setInstance(monitor.getIp() + ":" + monitor.getPort()); + list.add(request); + }); + } else { + Map map = MetricQuery.getMetricQueryMap(); + Set set = map.keySet(); + set.forEach(s -> { + MetricDataRequest request = new MetricDataRequest(); + String promQL = map.get(s); + request.setPromQL(promQL); + request.setSeriesName(s); + request.setInstance(monitor.getIp() + ":" + monitor.getPort()); + list.add(request); + }); + } } - public List queryReportResource(String reportId) { - List result = new ArrayList<>(); + public List queryReportResource(String reportId) { + List result = new ArrayList<>(); List resourceIdAndIndexes = extLoadTestReportMapper.selectResourceId(reportId); resourceIdAndIndexes.forEach(resourceIdAndIndex -> { - String[] split = org.apache.commons.lang3.StringUtils.split(resourceIdAndIndex, "_"); + String[] split = StringUtils.split(resourceIdAndIndex, "_"); String resourceId = split[0]; TestResource testResource = testResourceService.getTestResource(resourceId); if (testResource == null) { return; } String configuration = testResource.getConfiguration(); - if (org.apache.commons.lang3.StringUtils.isBlank(configuration)) { + if (StringUtils.isBlank(configuration)) { return; } NodeDTO dto = JSON.parseObject(configuration, NodeDTO.class); if (StringUtils.isNotBlank(dto.getIp())) { Integer monitorPort = dto.getMonitorPort(); int port = monitorPort == null ? 9100 : monitorPort; - result.add(dto.getIp() + ":" + port); + Monitor monitor = new Monitor(); + monitor.setIp(dto.getIp()); + monitor.setPort(port); + result.add(monitor); } }); @@ -247,11 +271,14 @@ public class MetricQueryService { } for (int i = 0; i < monitorParams.size(); i++) { - Monitor monitor = monitorParams.getObject(i, Monitor.class); - String instance = monitor.getIp() + ":" + monitor.getPort(); - if (!result.contains(instance)) { - result.add(instance); - } + JSONObject o = monitorParams.getJSONObject(i); + Monitor monitor = new Monitor(); + monitor.setIp(o.getString("ip")); + monitor.setName(o.getString("name")); + monitor.setPort(o.getInteger("port")); + monitor.setDescription(o.getString("description")); + monitor.setMonitorConfig(JSONObject.parseArray(o.getString("monitorConfig"), MonitorItem.class)); + result.add(monitor); } return result; diff --git a/backend/src/main/java/io/metersphere/track/dto/TestPlanLoadCaseDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestPlanLoadCaseDTO.java index 61ab2d96f0..98e275b03b 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestPlanLoadCaseDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestPlanLoadCaseDTO.java @@ -6,6 +6,7 @@ import io.metersphere.dto.LogDetailDTO; import io.metersphere.performance.base.*; import io.metersphere.performance.dto.LoadTestExportJmx; import io.metersphere.performance.dto.MetricData; +import io.metersphere.performance.dto.Monitor; import lombok.Getter; import lombok.Setter; @@ -42,7 +43,7 @@ public class TestPlanLoadCaseDTO extends TestPlanLoadCase { private List reportErrors; private List reportErrorsTop5; private List reportLogResource; - private List reportResource; + private List reportResource; private List metricData; } } diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 1dc1aaa717..b9b32e5225 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -41,6 +41,7 @@ import io.metersphere.notice.service.NoticeSendService; import io.metersphere.performance.base.*; import io.metersphere.performance.dto.LoadTestExportJmx; import io.metersphere.performance.dto.MetricData; +import io.metersphere.performance.dto.Monitor; import io.metersphere.performance.request.RunTestPlanRequest; import io.metersphere.performance.service.MetricQueryService; import io.metersphere.performance.service.PerformanceReportService; @@ -1573,7 +1574,7 @@ public class TestPlanService { response.setReportLogResource(reportLogResource); // performanceReportService.getReportLogs(reportId, resourceId); - List reportResource = metricQueryService.queryReportResource(reportId); + List reportResource = metricQueryService.queryReportResource(reportId); response.setReportResource(reportResource); List metricData = metricQueryService.queryMetric(reportId); response.setMetricData(metricData); diff --git a/backend/src/main/java/io/metersphere/xpack b/backend/src/main/java/io/metersphere/xpack index a6a66f87a5..6e2b1d3d7d 160000 --- a/backend/src/main/java/io/metersphere/xpack +++ b/backend/src/main/java/io/metersphere/xpack @@ -1 +1 @@ -Subproject commit a6a66f87a57346cdd7da22086bac5e82a7e47bdb +Subproject commit 6e2b1d3d7d79f985e6edf81eb593670b8da87465 diff --git a/frontend/src/business/components/performance/report/components/MonitorCard.vue b/frontend/src/business/components/performance/report/components/MonitorCard.vue index 20a7c1b0d0..0d53205ee5 100644 --- a/frontend/src/business/components/performance/report/components/MonitorCard.vue +++ b/frontend/src/business/components/performance/report/components/MonitorCard.vue @@ -6,10 +6,10 @@ + v-for="item in instances" + :key="item.ip+item.port" + :value="item.ip+':'+item.port"> + {{ item.ip }} {{ item.name }} @@ -35,47 +35,47 @@ + :data="tableData" + stripe + border + style="width: 100%"> + prop="label" + label="Label" + sortable> @@ -97,6 +97,14 @@ import { } from "@/network/load-test"; const color = ['#60acfc', '#32d3eb', '#5bc49f', '#feb64d', '#ff7c7c', '#9287e7', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3']; +const checkList = ['CPU', 'Memory', 'Disk', 'Network In', 'Network Out']; +const checkOptions = [ + {key: 'cpu', label: 'CPU'}, + {key: 'memory', label: 'Memory'}, + {key: 'disk', label: 'Disk'}, + {key: 'netIn', label: 'Network In'}, + {key: 'netOut', label: 'Network Out'} +]; export default { name: "MonitorCard", @@ -113,14 +121,8 @@ export default { instances: [], data: [], tableData: [], - checkList: ['CPU', 'Memory', 'Disk', 'Network In', 'Network Out'], - checkOptions: [ - {key: 'cpu', label: 'CPU'}, - {key: 'memory', label: 'Memory'}, - {key: 'disk', label: 'Disk'}, - {key: 'netIn', label: 'Network In'}, - {key: 'netOut', label: 'Network Out'} - ], + checkList: checkList, + checkOptions: checkOptions, baseOption: { color: color, grid: { @@ -175,14 +177,14 @@ export default { // this.init = true; if (this.planReportTemplate) { this.instances = this.planReportTemplate.reportResource; - this.currentInstance = this.instances[0]; + this.currentInstance = this.instances[0].ip + ":" + this.instances[0].port; this.data = this.planReportTemplate.metricData; this.totalOption = this.getOption(this.currentInstance); } else if (this.isShare) { getSharePerformanceMetricQueryResource(this.shareId, this.id).then(response => { this.instances = response.data.data; if (!this.currentInstance) { - this.currentInstance = this.instances[0]; + this.currentInstance = this.instances[0].ip + ":" + this.instances[0].port; } getSharePerformanceMetricQuery(this.shareId, this.id).then(result => { if (result) { @@ -196,7 +198,7 @@ export default { getPerformanceMetricQueryResource(this.id).then(response => { this.instances = response.data.data; if (!this.currentInstance) { - this.currentInstance = this.instances[0]; + this.currentInstance = this.instances[0].ip + ":" + this.instances[0].port; } getPerformanceMetricQuery(this.id).then(result => { if (result) { @@ -211,6 +213,18 @@ export default { } }, handleChecked(id) { + let curr = this.instances.filter(instance => id === instance.ip + ":" + instance.port)[0]; + if (curr.monitorConfig) { + this.checkList = []; + this.checkOptions = curr.monitorConfig.filter(mc => mc.value && mc.name) + .map(mc => { + this.checkList.push(mc.name); + return {key: mc.name, label: mc.name,}; + }); + } else { + this.checkOptions = checkOptions; + this.checkList = checkList; + } this.totalOption = {}; this.$nextTick(() => { this.totalOption = this.getOption(id); diff --git a/frontend/src/business/components/performance/test/components/EditMonitor.vue b/frontend/src/business/components/performance/test/components/EditMonitor.vue index 0a5aa23364..5ea2653f17 100644 --- a/frontend/src/business/components/performance/test/components/EditMonitor.vue +++ b/frontend/src/business/components/performance/test/components/EditMonitor.vue @@ -8,27 +8,36 @@ :destroy-on-close="true" v-loading="result.loading" > - - - - -

监控配置

- - - - - - - - - - - - - - - -
+
+ + + + +

监控配置

+ + + + + + + + + + + + + + + +

监控项

+ + + + + +
+