From f101ce900e999d74fe3b70caaca2f66701f6dbf1 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Wed, 14 Apr 2021 16:06:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E5=9B=BE=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/MetricQueryService.java | 11 +++--- .../report/components/MonitorCard.vue | 35 +++++++++++++------ 2 files changed, 31 insertions(+), 15 deletions(-) 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 514f2f9673..536329d102 100644 --- a/backend/src/main/java/io/metersphere/performance/service/MetricQueryService.java +++ b/backend/src/main/java/io/metersphere/performance/service/MetricQueryService.java @@ -69,13 +69,14 @@ public class MetricQueryService { return metricDataList; } - + private List queryPrometheusMetric(String promQL, String seriesName, long startTime, long endTime, int step, String instance) { DecimalFormat df = new DecimalFormat("#.###"); String start = df.format(startTime / 1000.0); String end = df.format(endTime / 1000.0); JSONObject response = restTemplate.getForObject(prometheusHost + "/api/v1/query_range?query={promQL}&start={start}&end={end}&step={step}", JSONObject.class, promQL, start, end, step); + LogUtil.info(prometheusHost + "/api/v1/query_range?query={" + promQL + "}&start={" + start + "}&end{" + end + "}&step={" + step + "}"); return handleResult(seriesName, response, instance); } @@ -90,8 +91,7 @@ public class MetricQueryService { if (result.size() > 1) { result.forEach(rObject -> { - JSONObject resultObject = new JSONObject((Map)rObject); -// JSONObject resultObject = JSONObject.parseObject(rObject.toString()); + JSONObject resultObject = new JSONObject((Map) rObject); JSONObject metrics = resultObject.getJSONObject("metric"); if (metrics != null && metrics.size() > 0) { @@ -108,7 +108,7 @@ public class MetricQueryService { List timestamps = new ArrayList<>(); List values = new ArrayList<>(); - JSONObject resultObject = new JSONObject((Map)rObject); + JSONObject resultObject = new JSONObject((Map) rObject); JSONObject metrics = resultObject.getJSONObject("metric"); JSONArray jsonArray = resultObject.getJSONArray("values"); jsonArray.forEach(value -> { @@ -117,6 +117,7 @@ public class MetricQueryService { try { timestamps.add(DateUtils.getTimeString((long) (timestamp * 1000))); } catch (Exception e) { + LogUtil.error(e.getMessage(), e); e.printStackTrace(); } values.add(ja.getDouble(1)); @@ -165,7 +166,7 @@ public class MetricQueryService { metricRequest.setStartTime(startTime.getTime()); metricRequest.setEndTime(endTime.getTime()); } catch (Exception e) { - LogUtil.error(e, e.getMessage()); + LogUtil.error(e.getMessage(), e); e.printStackTrace(); } diff --git a/frontend/src/business/components/performance/report/components/MonitorCard.vue b/frontend/src/business/components/performance/report/components/MonitorCard.vue index 1802cd262f..5536b95dd6 100644 --- a/frontend/src/business/components/performance/report/components/MonitorCard.vue +++ b/frontend/src/business/components/performance/report/components/MonitorCard.vue @@ -71,11 +71,14 @@ export default { let option = { title: { left: 'center', - text: 'CPU', + text: 'CPU使用率', textStyle: { - color: '#99743C' + color: '#8492a6' }, }, + tooltip: { + trigger: 'axis' + }, xAxis: { type: 'category', data: xAxis @@ -102,11 +105,14 @@ export default { let option = { title: { left: 'center', - text: 'Disk', + text: '磁盘使用率', textStyle: { - color: '#99743C' + color: '#8492a6' }, }, + tooltip: { + trigger: 'axis' + }, xAxis: { type: 'category', data: xAxis @@ -133,11 +139,14 @@ export default { let option = { title: { left: 'center', - text: 'NetIn', + text: '入口流量', textStyle: { - color: '#99743C' + color: '#8492a6' }, }, + tooltip: { + trigger: 'axis' + }, xAxis: { type: 'category', data: xAxis @@ -164,11 +173,14 @@ export default { let option = { title: { left: 'center', - text: 'NetOut', + text: '出口流量', textStyle: { - color: '#99743C' + color: '#8492a6' }, }, + tooltip: { + trigger: 'axis' + }, xAxis: { type: 'category', data: xAxis @@ -195,11 +207,14 @@ export default { let option = { title: { left: 'center', - text: 'Memory', + text: '内存使用率', textStyle: { - color: '#99743C' + color: '#8492a6' }, }, + tooltip: { + trigger: 'axis' + }, xAxis: { type: 'category', data: xAxis