diff --git a/frontend/src/business/components/performance/report/components/MonitorCard.vue b/frontend/src/business/components/performance/report/components/MonitorCard.vue index fd32f86fc9..20a7c1b0d0 100644 --- a/frontend/src/business/components/performance/report/components/MonitorCard.vue +++ b/frontend/src/business/components/performance/report/components/MonitorCard.vue @@ -1,28 +1,88 @@ @@ -30,8 +90,10 @@ import MsChart from "@/business/components/common/chart/MsChart"; import { - getPerformanceMetricQuery, getPerformanceMetricQueryResource, - getSharePerformanceMetricQuery, getSharePerformanceMetricQueryResource, + getPerformanceMetricQuery, + getPerformanceMetricQueryResource, + getSharePerformanceMetricQuery, + getSharePerformanceMetricQueryResource, } from "@/network/load-test"; const color = ['#60acfc', '#32d3eb', '#5bc49f', '#feb64d', '#ff7c7c', '#9287e7', '#ca8622', '#bda29a', '#6e7074', '#546570', '#c4ccd3']; @@ -47,8 +109,10 @@ export default { id: '', init: false, loading: false, + currentInstance: '', instances: [], data: [], + tableData: [], checkList: ['CPU', 'Memory', 'Disk', 'Network In', 'Network Out'], checkOptions: [ {key: 'cpu', label: 'CPU'}, @@ -96,7 +160,8 @@ export default { ], series: [] }, - totalOption: {} + totalOption: {}, + seriesData: [], }; }, created() { @@ -110,25 +175,36 @@ export default { // this.init = true; if (this.planReportTemplate) { this.instances = this.planReportTemplate.reportResource; + this.currentInstance = this.instances[0]; this.data = this.planReportTemplate.metricData; - this.totalOption = this.getOption(this.instances[0]); - } else if (this.isShare){ + 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]; + } getSharePerformanceMetricQuery(this.shareId, this.id).then(result => { if (result) { this.data = result.data.data; - this.totalOption = this.getOption(this.instances[0]); + this.totalOption = this.getOption(this.currentInstance); + this.changeDataZoom({start: 0, end: 100}); } }); }); } else { getPerformanceMetricQueryResource(this.id).then(response => { this.instances = response.data.data; + if (!this.currentInstance) { + this.currentInstance = this.instances[0]; + } getPerformanceMetricQuery(this.id).then(result => { if (result) { this.data = result.data.data; - this.totalOption = this.getOption(this.instances[0]); + this.$nextTick(() => { + this.totalOption = this.getOption(this.currentInstance); + this.changeDataZoom({start: 0, end: 100}); + }); } }); }); @@ -138,12 +214,7 @@ export default { this.totalOption = {}; this.$nextTick(() => { this.totalOption = this.getOption(id); - }); - }, - clickTabs(tab) { - this.totalOption = {}; - this.$nextTick(() => { - this.totalOption = this.getOption(tab.label); + this.changeDataZoom({start: 0, end: 100}); }); }, getOption(id) { @@ -165,15 +236,22 @@ export default { this.baseOption.xAxis.data = d.timestamps; let yAxis = d.values.map(v => v.toFixed(2)); + let data = []; + for (let i = 0; i < d.timestamps.length; i++) { + data.push([d.timestamps[i], yAxis[i]]); + } + legend.push(name); series.push({ name: name, - data: yAxis, + data: data, type: 'line', yAxisIndex: yAxisIndex, smooth: true, sampling: 'lttb', }); + + this.seriesData = series; } }); } @@ -181,6 +259,55 @@ export default { this.baseOption.series = series; return this.baseOption; }, + changeDataZoom(params) { + let start = params.start / 100; + let end = params.end / 100; + if (params.batch) { + start = params.batch[0].start / 100; + end = params.batch[0].end / 100; + } + + let tableData = []; + for (let i = 0; i < this.seriesData.length; i++) { + let sub = this.seriesData[i].data, label = this.seriesData[i].name; + let len = 0; + let min, avg, max, sum = 0, startTime, endTime; + for (let j = 0; j < sub.length; j++) { + let time = sub[j][0]; + let value = Number.parseFloat(sub[j][1]); + let index = (j / (sub.length - 1)).toFixed(2); + if (index < start) { + continue; + } + if (index >= end) { + endTime = time; + break; + } + + if (!startTime) { + startTime = time; + } + + if (!min && !max) { + min = max = value; + } + + if (min > value) { + min = value; + } + if (max < value) { + max = value; + } + sum += value; + + len++; // 实际 len + } + + avg = (sum / len).toFixed(2); + tableData.push({label, min, max, avg, startTime, endTime}); + } + this.tableData = tableData; + }, }, watch: { '$route'(to) {