提交 192f7922 编写于 作者: S shiziyuan9527

报告-错误记录

上级 a1f24eca
......@@ -65,7 +65,7 @@ public class PerformanceReportController {
}
@GetMapping("/content/errors_top5/{reportId}")
public ErrorsTop5DTO getReportErrorsTop5(@PathVariable String reportId) {
public List<ErrorsTop5> getReportErrorsTop5(@PathVariable String reportId) {
return reportService.getReportErrorsTOP5(reportId);
}
......
......@@ -7,7 +7,9 @@ import io.metersphere.report.base.*;
import io.metersphere.report.dto.ErrorsTop5DTO;
import io.metersphere.report.parse.ResultDataParse;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.report.processor.ErrorsSummaryConsumer;
import org.apache.jmeter.report.processor.StatisticsSummaryConsumer;
import org.apache.jmeter.report.processor.Top5ErrorsBySamplerConsumer;
import org.apache.jmeter.report.processor.graph.impl.ActiveThreadsGraphConsumer;
import org.apache.jmeter.report.processor.graph.impl.HitsPerSecondGraphConsumer;
import org.apache.jmeter.report.processor.graph.impl.ResponseTimeOverTimeGraphConsumer;
......@@ -47,104 +49,25 @@ public class GenerateReport {
return null;
}
public static List<Errors> getErrorsList(String jtlString) {
List<Metric> totalMetricList = resolver(jtlString);
List<Errors> errorsList = new ArrayList<>();
DecimalFormat decimalFormat = new DecimalFormat("0.00");
List<Metric> falseList = new ArrayList<>();
for (Metric metric : totalMetricList) {
if (StringUtils.equals("false", metric.getSuccess())) {
falseList.add(metric);
}
}
Map<String, List<Metric>> jtlMap = falseList.stream().collect(Collectors.groupingBy(GenerateReport::getResponseCodeAndFailureMessage));
for (Map.Entry<String, List<Metric>> next : jtlMap.entrySet()) {
String key = next.getKey();
List<Metric> metricList = next.getValue();
Errors errors = new Errors();
errors.setErrorType(key);
errors.setErrorNumber(String.valueOf(metricList.size()));
int errorSize = metricList.size();
int errorAllSize = falseList.size();
int allSamples = totalMetricList.size();
errors.setPrecentOfErrors(decimalFormat.format((double) errorSize / errorAllSize * 100) + "%");
errors.setPrecentOfAllSamples(decimalFormat.format((double) errorSize / allSamples * 100) + "%");
errorsList.add(errors);
}
Map<String, Object> statisticsDataMap = ResultDataParse.getSummryDataMap(jtlString, new ErrorsSummaryConsumer());
return ResultDataParse.summaryMapParsing(statisticsDataMap, Errors.class);
}
return errorsList;
public static List<ErrorsTop5> getErrorsTop5List(String jtlString) {
Map<String, Object> statisticsDataMap = ResultDataParse.getSummryDataMap(jtlString, new Top5ErrorsBySamplerConsumer());
return ResultDataParse.summaryMapParsing(statisticsDataMap, ErrorsTop5.class);
}
public static List<Statistics> getRequestStatistics(String jtlString) {
Map<String, Object> statisticsDataMap = ResultDataParse.getSummryDataMap(jtlString, new StatisticsSummaryConsumer());
return ResultDataParse.summaryMapParsing(statisticsDataMap);
return ResultDataParse.summaryMapParsing(statisticsDataMap, Statistics.class);
}
private static String getResponseCodeAndFailureMessage(Metric metric) {
return metric.getResponseCode() + "/" + metric.getResponseMessage();
}
public static ErrorsTop5DTO getErrorsTop5DTO(String jtlString) {
List<Metric> totalMetricList = resolver(jtlString);
ErrorsTop5DTO top5DTO = new ErrorsTop5DTO();
List<ErrorsTop5> errorsTop5s = new ArrayList<>();
List<Metric> falseList = Objects.requireNonNull(totalMetricList).stream()
.filter(metric -> StringUtils.equals("false", metric.getSuccess()))
.collect(Collectors.toList());
Map<String, List<Metric>> collect = falseList.stream()
.collect(Collectors.groupingBy(GenerateReport::getResponseCodeAndFailureMessage));
for (Map.Entry<String, List<Metric>> next : collect.entrySet()) {
String key = next.getKey();
List<Metric> metricList = next.getValue();
List<Metric> list = new ArrayList<>();
for (Metric metric : totalMetricList) {
if (StringUtils.equals(metric.getLabel(), metricList.get(0).getLabel())) {
list.add(metric);
}
}
ErrorsTop5 errorsTop5 = new ErrorsTop5();
errorsTop5.setSamples(String.valueOf(list.size()));
errorsTop5.setSample(metricList.get(0).getLabel());
errorsTop5.setErrors(String.valueOf(metricList.size()));
errorsTop5.setErrorsAllSize(metricList.size());
errorsTop5.setError(key);
errorsTop5s.add(errorsTop5);
}
errorsTop5s.sort((t0, t1) -> t1.getErrorsAllSize().compareTo(t0.getErrorsAllSize()));
if (errorsTop5s.size() >= ERRORS_TOP_SIZE) {
errorsTop5s = errorsTop5s.subList(0, ERRORS_TOP_SIZE);
}
top5DTO.setLabel("Total");
top5DTO.setErrorsTop5List(errorsTop5s);
top5DTO.setTotalSamples(String.valueOf(totalMetricList.size()));
top5DTO.setTotalErrors(String.valueOf(falseList.size()));
int size = errorsTop5s.size();
// Total行 信息
top5DTO.setError1(size > 0 ? errorsTop5s.get(0).getError() : null);
top5DTO.setError1Size(size > 0 ? errorsTop5s.get(0).getErrors() : null);
top5DTO.setError2(size > 1 ? errorsTop5s.get(1).getError() : null);
top5DTO.setError2Size(size > 1 ? errorsTop5s.get(1).getErrors() : null);
top5DTO.setError3(size > 2 ? errorsTop5s.get(2).getError() : null);
top5DTO.setError3Size(size > 2 ? errorsTop5s.get(2).getErrors() : null);
top5DTO.setError4(size > 3 ? errorsTop5s.get(3).getError() : null);
top5DTO.setError4Size(size > 3 ? errorsTop5s.get(3).getErrors() : null);
top5DTO.setError5(size > 4 ? errorsTop5s.get(4).getError() : null);
top5DTO.setError5Size(size > 4 ? errorsTop5s.get(4).getErrors() : null);
return top5DTO;
}
public static TestOverview getTestOverview(String jtlString) {
TestOverview testOverview = new TestOverview();
DecimalFormat decimalFormat = new DecimalFormat("0.00");
......
......@@ -4,9 +4,17 @@ public class ErrorsTop5 {
private String sample;
private String samples;
private Integer errorsAllSize;
private String error;
private String errors;
private String errorsAllSize;
private String error1;
private String error1Size;
private String error2;
private String error2Size;
private String error3;
private String error3Size;
private String error4;
private String error4Size;
private String error5;
private String error5Size;
public String getSample() {
return sample;
......@@ -24,27 +32,91 @@ public class ErrorsTop5 {
this.samples = samples;
}
public Integer getErrorsAllSize() {
public String getErrorsAllSize() {
return errorsAllSize;
}
public void setErrorsAllSize(Integer errorsAllSize) {
public void setErrorsAllSize(String errorsAllSize) {
this.errorsAllSize = errorsAllSize;
}
public String getError() {
return error;
public String getError1() {
return error1;
}
public void setError(String error) {
this.error = error;
public void setError1(String error1) {
this.error1 = error1;
}
public String getErrors() {
return errors;
public String getError1Size() {
return error1Size;
}
public void setErrors(String errors) {
this.errors = errors;
public void setError1Size(String error1Size) {
this.error1Size = error1Size;
}
public String getError2() {
return error2;
}
public void setError2(String error2) {
this.error2 = error2;
}
public String getError2Size() {
return error2Size;
}
public void setError2Size(String error2Size) {
this.error2Size = error2Size;
}
public String getError3() {
return error3;
}
public void setError3(String error3) {
this.error3 = error3;
}
public String getError3Size() {
return error3Size;
}
public void setError3Size(String error3Size) {
this.error3Size = error3Size;
}
public String getError4() {
return error4;
}
public void setError4(String error4) {
this.error4 = error4;
}
public String getError4Size() {
return error4Size;
}
public void setError4Size(String error4Size) {
this.error4Size = error4Size;
}
public String getError5() {
return error5;
}
public void setError5(String error5) {
this.error5 = error5;
}
public String getError5Size() {
return error5Size;
}
public void setError5Size(String error5Size) {
this.error5Size = error5Size;
}
}
package io.metersphere.report.parse;
import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.MsJMeterUtils;
import io.metersphere.report.base.ChartsData;
import io.metersphere.report.base.Statistics;
import io.metersphere.report.base.SummaryData;
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.*;
import org.apache.jmeter.report.processor.graph.AbstractOverTimeGraphConsumer;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.text.ParseException;
......@@ -26,8 +22,8 @@ public class ResultDataParse {
private static final String DATE_TIME_PATTERN = "yyyy/MM/dd HH:mm:ss";
private static final String TIME_PATTERN = "HH:mm:ss";
public static List<Statistics> summaryMapParsing(Map<String, Object> map) {
List<Statistics> statisticsList = new ArrayList<>();
public static <T> List<T> summaryMapParsing(Map<String, Object> map, Class<T> clazz) {
List<T> list = new ArrayList<>();
for (String key : map.keySet()) {
MapResultData mapResultData = (MapResultData) map.get(key);
ListResultData items = (ListResultData) mapResultData.getResult("items");
......@@ -39,21 +35,24 @@ public class ResultDataParse {
String[] strArray = new String[size];
for (int j = 0; j < size; j++) {
ValueResultData valueResultData = (ValueResultData) data.get(j);
String accept = valueResultData.accept(new JsonizerVisitor());
strArray[j] = accept.replace("\\", "");
if (valueResultData.getValue() == null) {
strArray[j] = "";
} else {
String accept = valueResultData.accept(new JsonizerVisitor());
strArray[j] = accept.replace("\\", "");
}
}
Statistics statistics = null;
T t = null;
try {
statistics = setParam(Statistics.class, strArray);
t = setParam(clazz, strArray);
} catch (Exception e) {
e.printStackTrace();
}
statisticsList.add(statistics);
list.add(t);
}
}
}
return statisticsList;
return list;
}
public static List<ChartsData> graphMapParsing(Map<String, Object> map, String seriesName) {
......
......@@ -96,12 +96,12 @@ public class ReportService {
return errors;
}
public ErrorsTop5DTO getReportErrorsTOP5(String id) {
public List<ErrorsTop5> getReportErrorsTOP5(String id) {
checkReportStatus(id);
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id);
String content = loadTestReport.getContent();
ErrorsTop5DTO errors = GenerateReport.getErrorsTop5DTO(content);
return errors;
List<ErrorsTop5> errorsTop5 = GenerateReport.getErrorsTop5List(content);
return errorsTop5;
}
public TestOverview getTestOverview(String id) {
......
......@@ -39,7 +39,6 @@
stripe
style="width: 100%"
show-summary
:summary-method="getSummaries"
>
<el-table-column
prop="sample"
......@@ -59,62 +58,65 @@
width="100"
>
</el-table-column>
<el-table-column
prop="error"
prop="error1"
label="Error"
width="400"
>
</el-table-column>
<el-table-column
prop="errors"
prop="error1Size"
label="#Errors"
width="100"
>
</el-table-column>
<el-table-column
prop="Error"
prop="error2"
label="Error"
width="400"
>
</el-table-column>
<el-table-column
prop="#Errors"
prop="error2Size"
label="#Errors"
width="100"
>
</el-table-column>
<el-table-column
prop="Error"
prop="error3"
label="Error"
width="400"
>
</el-table-column>
<el-table-column
prop="#Errors"
prop="error3Size"
label="#Errors"
width="100"
>
</el-table-column>
<el-table-column
prop="Error"
prop="error4"
label="Error"
width="400"
>
</el-table-column>
<el-table-column
prop="#Errors"
prop="error4Size"
label="#Errors"
width="100"
>
</el-table-column>
<el-table-column
prop="Error"
prop="error5"
label="Error"
width="400"
>
</el-table-column>
<el-table-column
prop="#Errors"
prop="error5Size"
label="#Errors"
width="100"
>
......@@ -128,22 +130,7 @@
name: "ErrorLog",
data() {
return {
tableData: [{},{},{},{},{}],
errorTotal: {
label: '',
totalSamples: '',
totalErrors: '',
error1: '',
error1Size: '',
error2: '',
error2Size: '',
error3: '',
error3Size: '',
error4: '',
error4Size: '',
error5: '',
error5Size: ''
},
tableData: [],
errorTop5: []
}
},
......@@ -153,33 +140,14 @@
this.tableData = res.data;
})
this.$get("/performance/report/content/errors_top5/" + this.id, res => {
this.errorTotal = res.data
this.errorTop5 = res.data.errorsTop5List;
this.errorTop5 = res.data;
})
},
getSummaries () {
const sums = []
sums[0] = this.errorTotal.label;
sums[1] = this.errorTotal.totalSamples;
sums[2] = this.errorTotal.totalErrors;
sums[3] = this.errorTotal.error1;
sums[4] = this.errorTotal.error1Size;
sums[5] = this.errorTotal.error2;
sums[6] = this.errorTotal.error2Size;
sums[7] = this.errorTotal.error3;
sums[8] = this.errorTotal.error3Size;
sums[9] = this.errorTotal.error4;
sums[10] = this.errorTotal.error4Size;
sums[11] = this.errorTotal.error5;
sums[12] = this.errorTotal.error5Size;
return sums;
}
},
watch: {
status() {
if ("Completed" === this.status) {
this.initTableData()
this.getSummaries()
}
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册