refactor(性能测试): 修改图表

This commit is contained in:
shiziyuan9527 2021-04-14 16:06:25 +08:00 committed by 刘瑞斌
parent 1807ff3538
commit f101ce900e
2 changed files with 31 additions and 15 deletions

View File

@ -69,13 +69,14 @@ public class MetricQueryService {
return metricDataList; return metricDataList;
} }
private List<MetricData> queryPrometheusMetric(String promQL, String seriesName, long startTime, long endTime, int step, String instance) { private List<MetricData> queryPrometheusMetric(String promQL, String seriesName, long startTime, long endTime, int step, String instance) {
DecimalFormat df = new DecimalFormat("#.###"); DecimalFormat df = new DecimalFormat("#.###");
String start = df.format(startTime / 1000.0); String start = df.format(startTime / 1000.0);
String end = df.format(endTime / 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); 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); return handleResult(seriesName, response, instance);
} }
@ -90,8 +91,7 @@ public class MetricQueryService {
if (result.size() > 1) { if (result.size() > 1) {
result.forEach(rObject -> { result.forEach(rObject -> {
JSONObject resultObject = new JSONObject((Map)rObject); JSONObject resultObject = new JSONObject((Map) rObject);
// JSONObject resultObject = JSONObject.parseObject(rObject.toString());
JSONObject metrics = resultObject.getJSONObject("metric"); JSONObject metrics = resultObject.getJSONObject("metric");
if (metrics != null && metrics.size() > 0) { if (metrics != null && metrics.size() > 0) {
@ -108,7 +108,7 @@ public class MetricQueryService {
List<String> timestamps = new ArrayList<>(); List<String> timestamps = new ArrayList<>();
List<Double> values = new ArrayList<>(); List<Double> values = new ArrayList<>();
JSONObject resultObject = new JSONObject((Map)rObject); JSONObject resultObject = new JSONObject((Map) rObject);
JSONObject metrics = resultObject.getJSONObject("metric"); JSONObject metrics = resultObject.getJSONObject("metric");
JSONArray jsonArray = resultObject.getJSONArray("values"); JSONArray jsonArray = resultObject.getJSONArray("values");
jsonArray.forEach(value -> { jsonArray.forEach(value -> {
@ -117,6 +117,7 @@ public class MetricQueryService {
try { try {
timestamps.add(DateUtils.getTimeString((long) (timestamp * 1000))); timestamps.add(DateUtils.getTimeString((long) (timestamp * 1000)));
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage(), e);
e.printStackTrace(); e.printStackTrace();
} }
values.add(ja.getDouble(1)); values.add(ja.getDouble(1));
@ -165,7 +166,7 @@ public class MetricQueryService {
metricRequest.setStartTime(startTime.getTime()); metricRequest.setStartTime(startTime.getTime());
metricRequest.setEndTime(endTime.getTime()); metricRequest.setEndTime(endTime.getTime());
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e, e.getMessage()); LogUtil.error(e.getMessage(), e);
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -71,11 +71,14 @@ export default {
let option = { let option = {
title: { title: {
left: 'center', left: 'center',
text: 'CPU', text: 'CPU使用率',
textStyle: { textStyle: {
color: '#99743C' color: '#8492a6'
}, },
}, },
tooltip: {
trigger: 'axis'
},
xAxis: { xAxis: {
type: 'category', type: 'category',
data: xAxis data: xAxis
@ -102,11 +105,14 @@ export default {
let option = { let option = {
title: { title: {
left: 'center', left: 'center',
text: 'Disk', text: '磁盘使用率',
textStyle: { textStyle: {
color: '#99743C' color: '#8492a6'
}, },
}, },
tooltip: {
trigger: 'axis'
},
xAxis: { xAxis: {
type: 'category', type: 'category',
data: xAxis data: xAxis
@ -133,11 +139,14 @@ export default {
let option = { let option = {
title: { title: {
left: 'center', left: 'center',
text: 'NetIn', text: '入口流量',
textStyle: { textStyle: {
color: '#99743C' color: '#8492a6'
}, },
}, },
tooltip: {
trigger: 'axis'
},
xAxis: { xAxis: {
type: 'category', type: 'category',
data: xAxis data: xAxis
@ -164,11 +173,14 @@ export default {
let option = { let option = {
title: { title: {
left: 'center', left: 'center',
text: 'NetOut', text: '出口流量',
textStyle: { textStyle: {
color: '#99743C' color: '#8492a6'
}, },
}, },
tooltip: {
trigger: 'axis'
},
xAxis: { xAxis: {
type: 'category', type: 'category',
data: xAxis data: xAxis
@ -195,11 +207,14 @@ export default {
let option = { let option = {
title: { title: {
left: 'center', left: 'center',
text: 'Memory', text: '内存使用率',
textStyle: { textStyle: {
color: '#99743C' color: '#8492a6'
}, },
}, },
tooltip: {
trigger: 'axis'
},
xAxis: { xAxis: {
type: 'category', type: 'category',
data: xAxis data: xAxis