修改响应时间图表
This commit is contained in:
parent
eb7c2ddba0
commit
0ed0021895
|
@ -11,10 +11,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.apache.jmeter.report.core.Sample;
|
||||
import org.apache.jmeter.report.core.SampleMetadata;
|
||||
import org.apache.jmeter.report.dashboard.JsonizerVisitor;
|
||||
import org.apache.jmeter.report.processor.ListResultData;
|
||||
import org.apache.jmeter.report.processor.MapResultData;
|
||||
import org.apache.jmeter.report.processor.ResultData;
|
||||
import org.apache.jmeter.report.processor.SampleContext;
|
||||
import org.apache.jmeter.report.processor.*;
|
||||
import org.apache.jmeter.report.processor.graph.AbstractOverTimeGraphConsumer;
|
||||
import org.apache.jmeter.report.processor.graph.impl.ActiveThreadsGraphConsumer;
|
||||
import org.apache.jmeter.report.processor.graph.impl.HitsPerSecondGraphConsumer;
|
||||
|
@ -346,61 +343,6 @@ public class JtlResolver {
|
|||
return testOverview;
|
||||
}
|
||||
|
||||
|
||||
// public static List<ChartsData> getLoadChartData(String jtlString) {
|
||||
// List<ChartsData> chartsDataList = new ArrayList<>();
|
||||
// List<Metric> totalMetricList = JtlResolver.resolver(jtlString);
|
||||
//
|
||||
// if (totalMetricList != null) {
|
||||
// for (Metric metric : totalMetricList) {
|
||||
// metric.setTimestamp(stampToDate(DATE_TIME_PATTERN, metric.getTimestamp()));
|
||||
// }
|
||||
// }
|
||||
// Map<String, List<Metric>> collect = Objects.requireNonNull(totalMetricList).stream().collect(Collectors.groupingBy(Metric::getTimestamp));
|
||||
// List<Map.Entry<String, List<Metric>>> entries = new ArrayList<>(collect.entrySet());
|
||||
//
|
||||
// for (Map.Entry<String, List<Metric>> entry : entries) {
|
||||
// int failSize = 0;
|
||||
// List<Metric> metrics = entry.getValue();
|
||||
// Map<String, List<Metric>> metricsMap = metrics.stream().collect(Collectors.groupingBy(Metric::getThreadName));
|
||||
// int maxUsers = metricsMap.size();
|
||||
// for (Metric metric : metrics) {
|
||||
// String isSuccess = metric.getSuccess();
|
||||
// if (!"true".equals(isSuccess)) {
|
||||
// failSize++;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// String timeStamp = "";
|
||||
// try {
|
||||
// timeStamp = formatDate(entry.getKey());
|
||||
// } catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// ChartsData chartsData = new ChartsData();
|
||||
// chartsData.setxAxis(timeStamp);
|
||||
// chartsData.setGroupName("hits");
|
||||
// chartsData.setyAxis(new BigDecimal(metrics.size() * 1.0 / maxUsers));
|
||||
// chartsDataList.add(chartsData);
|
||||
//
|
||||
// chartsData = new ChartsData();
|
||||
// chartsData.setxAxis(timeStamp);
|
||||
// chartsData.setGroupName("users");
|
||||
// chartsData.setyAxis(new BigDecimal(maxUsers));
|
||||
// chartsDataList.add(chartsData);
|
||||
//
|
||||
// chartsData = new ChartsData();
|
||||
// chartsData.setxAxis(timeStamp);
|
||||
// chartsData.setGroupName("errors");
|
||||
// chartsData.setyAxis(new BigDecimal(failSize));
|
||||
// chartsDataList.add(chartsData);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// return chartsDataList;
|
||||
// }
|
||||
|
||||
public static List<ChartsData> getLoadChartData(String jtlString) {
|
||||
Map<String, Object> activeThreadMap = getResultDataMap(jtlString, new ActiveThreadsGraphConsumer());
|
||||
Map<String, Object> hitsMap = getResultDataMap(jtlString, new HitsPerSecondGraphConsumer());
|
||||
|
@ -412,45 +354,6 @@ public class JtlResolver {
|
|||
return activeThreadList;
|
||||
}
|
||||
|
||||
// public static List<ChartsData> getResponseTimeChartData(String jtlString) {
|
||||
// List<ChartsData> chartsDataList = new ArrayList<>();
|
||||
// List<Metric> totalMetricList = JtlResolver.resolver(jtlString);
|
||||
//
|
||||
// totalMetricList.forEach(metric -> {
|
||||
// metric.setTimestamp(stampToDate(DATE_TIME_PATTERN, metric.getTimestamp()));
|
||||
// });
|
||||
//
|
||||
// Map<String, List<Metric>> metricMap = totalMetricList.stream().collect(Collectors.groupingBy(Metric::getTimestamp));
|
||||
// List<Map.Entry<String, List<Metric>>> entries = new ArrayList<>(metricMap.entrySet());
|
||||
//
|
||||
// for (Map.Entry<String, List<Metric>> entry : entries) {
|
||||
// List<Metric> metricList = entry.getValue();
|
||||
// Map<String, List<Metric>> metricsMap = metricList.stream().collect(Collectors.groupingBy(Metric::getThreadName));
|
||||
// int maxUsers = metricsMap.size();
|
||||
// int sumElapsedTime = metricList.stream().mapToInt(metric -> Integer.parseInt(metric.getElapsed())).sum();
|
||||
// String timeStamp = "";
|
||||
// try {
|
||||
// timeStamp = formatDate(entry.getKey());
|
||||
// } catch (ParseException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// ChartsData chartsData = new ChartsData();
|
||||
// chartsData.setxAxis(timeStamp);
|
||||
// chartsData.setGroupName("users");
|
||||
// chartsData.setyAxis(new BigDecimal(maxUsers));
|
||||
// chartsDataList.add(chartsData);
|
||||
//
|
||||
// ChartsData chartsData2 = new ChartsData();
|
||||
// chartsData2.setxAxis(timeStamp);
|
||||
// chartsData2.setGroupName("responseTime");
|
||||
// chartsData2.setyAxis(new BigDecimal(sumElapsedTime * 1.0 / metricList.size()));
|
||||
// chartsDataList.add(chartsData2);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// return chartsDataList;
|
||||
// }
|
||||
public static List<ChartsData> getResponseTimeChartData(String jtlString) {
|
||||
Map<String, Object> activeThreadMap = getResultDataMap(jtlString, new ActiveThreadsGraphConsumer());
|
||||
Map<String, Object> responseTimeMap = getResultDataMap(jtlString, new ResponseTimeOverTimeGraphConsumer());
|
||||
|
@ -464,13 +367,18 @@ public class JtlResolver {
|
|||
}
|
||||
|
||||
public static void mapResolver(Map<String, Object> map, List list, String seriesName) {
|
||||
// ThreadGroup-1
|
||||
for (String key : map.keySet()) {
|
||||
MapResultData mapResultData = (MapResultData) map.get(key);
|
||||
ResultData maxY = mapResultData.getResult("maxY");
|
||||
ListResultData series = (ListResultData) mapResultData.getResult("series");
|
||||
if (series.getSize() > 0) {
|
||||
MapResultData resultData = (MapResultData) series.get(0);
|
||||
for (int j = 0; j < series.getSize(); j++) {
|
||||
MapResultData resultData = (MapResultData) series.get(j);
|
||||
// data, isOverall, label, isController
|
||||
ListResultData data = (ListResultData) resultData.getResult("data");
|
||||
ValueResultData label = (ValueResultData) resultData.getResult("label");
|
||||
|
||||
if (data.getSize() > 0) {
|
||||
for (int i = 0; i < data.getSize(); i++) {
|
||||
ListResultData listResultData = (ListResultData) data.get(i);
|
||||
|
@ -488,16 +396,23 @@ public class JtlResolver {
|
|||
}
|
||||
chartsData.setxAxis(time);
|
||||
chartsData.setyAxis(new BigDecimal(split[1].trim()));
|
||||
if (series.getSize() == 1) {
|
||||
chartsData.setGroupName(seriesName);
|
||||
} else {
|
||||
chartsData.setGroupName((String) label.getValue());
|
||||
}
|
||||
list.add(chartsData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Object> getResultDataMap(String jtlString, AbstractOverTimeGraphConsumer timeGraphConsumer) {
|
||||
int row = 0;
|
||||
AbstractOverTimeGraphConsumer abstractOverTimeGraphConsumer = timeGraphConsumer;
|
||||
abstractOverTimeGraphConsumer.setGranularity(60000);
|
||||
// 这个路径不存在
|
||||
|
@ -513,7 +428,7 @@ public class JtlResolver {
|
|||
while (tokenizer.hasMoreTokens()) {
|
||||
String line = tokenizer.nextToken();
|
||||
String[] data = line.split(",", -1);
|
||||
Sample sample = new Sample(0, sampleMetaData, data);
|
||||
Sample sample = new Sample(row++, sampleMetaData, data);
|
||||
abstractOverTimeGraphConsumer.consume(sample, 0);
|
||||
}
|
||||
abstractOverTimeGraphConsumer.stopConsuming();
|
||||
|
|
|
@ -157,7 +157,8 @@
|
|||
this.$get("/performance/report/content/res_chart/" + this.id, res => {
|
||||
let data = res.data;
|
||||
let userList = data.filter(m => m.groupName === "users").map(m => m.yAxis);
|
||||
let responseTimeList = data.filter(m => m.groupName === "responseTime").map(m => m.yAxis);
|
||||
let responseTimeList = data.filter(m => m.groupName != "users").map(m => m.yAxis);
|
||||
let responseGroupNameList = data.filter(m => m.groupName != "users").map(m => m.groupName);
|
||||
let userMax = this._getChartMax(userList);
|
||||
let resMax = this._getChartMax(responseTimeList);
|
||||
let resOption = {
|
||||
|
@ -171,7 +172,24 @@
|
|||
},
|
||||
tooltip: {
|
||||
show: true,
|
||||
trigger: 'axis'
|
||||
trigger: 'axis',
|
||||
extraCssText: 'z-index: 999;',
|
||||
formatter: function (params, ticket, callback) {
|
||||
let result = "";
|
||||
let name = params[0].name;
|
||||
result += name + "<br/>";
|
||||
for (let i = 0; i < params.length; i++) {
|
||||
let seriesName = params[i].seriesName;
|
||||
if (seriesName.length > 100) {
|
||||
seriesName = seriesName.substring(0, 100);
|
||||
}
|
||||
let value = params[i].value;
|
||||
let marker = params[i].marker;
|
||||
result += marker + seriesName + ": " + value[1] + "<br/>";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
},
|
||||
legend: {},
|
||||
xAxis: {},
|
||||
|
@ -197,14 +215,12 @@
|
|||
{
|
||||
name: 'users',
|
||||
color: '#0CA74A',
|
||||
},
|
||||
{
|
||||
name: "responseTime",
|
||||
yAxisIndex: '1',
|
||||
color: '#99743C',
|
||||
}
|
||||
]
|
||||
}
|
||||
responseGroupNameList.forEach(item => {
|
||||
setting["series"].splice(0, 0, {name: item, yAxisIndex: '1'})
|
||||
})
|
||||
this.resOption = this.generateOption(resOption, data, setting);
|
||||
})
|
||||
},
|
||||
|
@ -229,10 +245,11 @@
|
|||
legend.push(name)
|
||||
series[name] = []
|
||||
}
|
||||
series[name].splice(xAxis.indexOf(item.xAxis), 0, [item.xAxis, Math.round(item.yAxis.toFixed(2))]);
|
||||
series[name].splice(xAxis.indexOf(item.xAxis), 0, [item.xAxis, item.yAxis.toFixed(2)]);
|
||||
})
|
||||
this.$set(option.legend, "data", legend);
|
||||
this.$set(option.legend, "bottom", 10);
|
||||
this.$set(option.legend, "type", "scroll");
|
||||
this.$set(option.legend, "bottom", "10px");
|
||||
this.$set(option.xAxis, "data", xAxis);
|
||||
for (let name in series) {
|
||||
let d = series[name];
|
||||
|
@ -259,9 +276,6 @@
|
|||
_getChartMax(arr) {
|
||||
const max = Math.max(...arr);
|
||||
return Math.ceil(max / 4.5) * 5;
|
||||
},
|
||||
_arraySort(a, b) {
|
||||
return a[0] > b[0];
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
|
Loading…
Reference in New Issue