Merge branch 'dev' of https://github.com/fit2cloudrd/metersphere-server into dev
This commit is contained in:
commit
653460fd8e
|
@ -9,7 +9,6 @@ import io.metersphere.commons.utils.Pager;
|
|||
import io.metersphere.controller.request.ReportRequest;
|
||||
import io.metersphere.dto.ReportDTO;
|
||||
import io.metersphere.report.base.*;
|
||||
import io.metersphere.report.dto.ErrorsTop5DTO;
|
||||
import io.metersphere.service.ReportService;
|
||||
import io.metersphere.user.SessionUtils;
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
|
@ -65,7 +64,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);
|
||||
}
|
||||
|
||||
|
|
|
@ -133,8 +133,10 @@ public class KubernetesTestEngine extends AbstractEngine {
|
|||
ClientCredential clientCredential = JSON.parseObject(configuration, ClientCredential.class);
|
||||
KubernetesProvider provider = new KubernetesProvider(JSON.toJSONString(clientCredential));
|
||||
provider.confirmNamespace(loadTest.getProjectId());
|
||||
String joblog = provider.getKubernetesClient().batch().jobs().inNamespace(loadTest.getProjectId()).withName("job-" + loadTest.getId()).getLog();
|
||||
try (KubernetesClient client = provider.getKubernetesClient()) {
|
||||
String joblog = client.batch().jobs().inNamespace(loadTest.getProjectId()).withName("job-" + loadTest.getId()).getLog();
|
||||
logs.put(clientCredential.getMasterUrl(), joblog);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
MSException.throwException(e);
|
||||
}
|
||||
|
|
|
@ -4,18 +4,17 @@ import com.opencsv.bean.CsvToBean;
|
|||
import com.opencsv.bean.CsvToBeanBuilder;
|
||||
import com.opencsv.bean.HeaderColumnNameMappingStrategy;
|
||||
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;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
|
@ -26,9 +25,7 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class GenerateReport {
|
||||
|
||||
private static final Integer ERRORS_TOP_SIZE = 5;
|
||||
private static final String DATE_TIME_PATTERN = "yyyy/MM/dd HH:mm:ss";
|
||||
private static final String TIME_PATTERN = "HH:mm:ss";
|
||||
|
||||
private static List<Metric> resolver(String jtlString) {
|
||||
HeaderColumnNameMappingStrategy<Metric> ms = new HeaderColumnNameMappingStrategy<>();
|
||||
|
@ -47,102 +44,19 @@ 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, Object> statisticsDataMap = ResultDataParse.getSummryDataMap(jtlString, new ErrorsSummaryConsumer());
|
||||
return ResultDataParse.summaryMapParsing(statisticsDataMap, Errors.class);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
return ResultDataParse.summaryMapParsing(statisticsDataMap, Statistics.class);
|
||||
}
|
||||
|
||||
public static TestOverview getTestOverview(String jtlString) {
|
||||
|
@ -233,7 +147,6 @@ public class GenerateReport {
|
|||
}
|
||||
|
||||
public static ReportTimeInfo getReportTimeInfo(String jtlString) {
|
||||
ReportTimeInfo reportTimeInfo = new ReportTimeInfo();
|
||||
List<Metric> totalLineList = GenerateReport.resolver(jtlString);
|
||||
|
||||
totalLineList.sort(Comparator.comparing(t0 -> Long.valueOf(t0.getTimestamp())));
|
||||
|
@ -244,16 +157,12 @@ public class GenerateReport {
|
|||
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
|
||||
String startTime = dtf.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(startTimeStamp)), ZoneId.systemDefault()));
|
||||
String endTime = dtf.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(endTimeStamp)), ZoneId.systemDefault()));
|
||||
reportTimeInfo.setStartTime(startTime);
|
||||
reportTimeInfo.setEndTime(endTime);
|
||||
|
||||
Date startDate = new Date(Long.parseLong(startTimeStamp));
|
||||
Date endDate = new Date(Long.parseLong(endTimeStamp));
|
||||
long timestamp = endDate.getTime() - startDate.getTime();
|
||||
reportTimeInfo.setDuration(String.valueOf(timestamp * 1.0 / 1000 / 60));
|
||||
|
||||
// todo 时间问题
|
||||
long seconds = Duration.between(Instant.ofEpochMilli(Long.parseLong(startTimeStamp)), Instant.ofEpochMilli(Long.parseLong(endTimeStamp))).getSeconds();
|
||||
ReportTimeInfo reportTimeInfo = new ReportTimeInfo();
|
||||
reportTimeInfo.setStartTime(startTime);
|
||||
reportTimeInfo.setEndTime(endTime);
|
||||
reportTimeInfo.setDuration(String.valueOf(seconds));
|
||||
|
||||
return reportTimeInfo;
|
||||
|
@ -265,14 +174,4 @@ public class GenerateReport {
|
|||
return localDateTime.format(dateTimeFormatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param "yyyy-MM-dd HH:mm:ss"
|
||||
* @return "HH:mm:ss"
|
||||
*/
|
||||
private static String formatDate(String dateString) throws ParseException {
|
||||
SimpleDateFormat before = new SimpleDateFormat(DATE_TIME_PATTERN);
|
||||
SimpleDateFormat after = new SimpleDateFormat(TIME_PATTERN);
|
||||
return after.format(before.parse(dateString));
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,136 +0,0 @@
|
|||
package io.metersphere.report.base;
|
||||
|
||||
public class RequestStatistics {
|
||||
|
||||
/**请求标签*/
|
||||
private String requestLabel;
|
||||
|
||||
/**压测请求数*/
|
||||
private Integer samples;
|
||||
|
||||
/**平均响应时间*/
|
||||
private String average;
|
||||
|
||||
/**平均点击率*/
|
||||
private String avgHits;
|
||||
|
||||
/**90% Line*/
|
||||
private String tp90;
|
||||
|
||||
/**95% Line*/
|
||||
private String tp95;
|
||||
|
||||
/**99% Line*/
|
||||
private String tp99;
|
||||
|
||||
/**最小请求时间 Min Response Time /ms */
|
||||
private String min;
|
||||
|
||||
/**最大请求时间 Max Response Time /ms */
|
||||
private String max;
|
||||
|
||||
/**吞吐量 KB/sec*/
|
||||
private String kbPerSec;
|
||||
|
||||
/**错误率 Error Percentage */
|
||||
private String errors;
|
||||
|
||||
/**错误个数*/
|
||||
private Integer ko;
|
||||
|
||||
public String getRequestLabel() {
|
||||
return requestLabel;
|
||||
}
|
||||
|
||||
public void setRequestLabel(String requestLabel) {
|
||||
this.requestLabel = requestLabel;
|
||||
}
|
||||
|
||||
public Integer getSamples() {
|
||||
return samples;
|
||||
}
|
||||
|
||||
public void setSamples(Integer samples) {
|
||||
this.samples = samples;
|
||||
}
|
||||
|
||||
public String getAverage() {
|
||||
return average;
|
||||
}
|
||||
|
||||
public void setAverage(String average) {
|
||||
this.average = average;
|
||||
}
|
||||
|
||||
public String getAvgHits() {
|
||||
return avgHits;
|
||||
}
|
||||
|
||||
public void setAvgHits(String avgHits) {
|
||||
this.avgHits = avgHits;
|
||||
}
|
||||
|
||||
public String getTp90() {
|
||||
return tp90;
|
||||
}
|
||||
|
||||
public void setTp90(String tp90) {
|
||||
this.tp90 = tp90;
|
||||
}
|
||||
|
||||
public String getTp95() {
|
||||
return tp95;
|
||||
}
|
||||
|
||||
public void setTp95(String tp95) {
|
||||
this.tp95 = tp95;
|
||||
}
|
||||
|
||||
public String getTp99() {
|
||||
return tp99;
|
||||
}
|
||||
|
||||
public void setTp99(String tp99) {
|
||||
this.tp99 = tp99;
|
||||
}
|
||||
|
||||
public String getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public void setMin(String min) {
|
||||
this.min = min;
|
||||
}
|
||||
|
||||
public String getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public void setMax(String max) {
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public String getKbPerSec() {
|
||||
return kbPerSec;
|
||||
}
|
||||
|
||||
public void setKbPerSec(String kbPerSec) {
|
||||
this.kbPerSec = kbPerSec;
|
||||
}
|
||||
|
||||
public String getErrors() {
|
||||
return errors;
|
||||
}
|
||||
|
||||
public void setErrors(String errors) {
|
||||
this.errors = errors;
|
||||
}
|
||||
|
||||
public Integer getKo() {
|
||||
return ko;
|
||||
}
|
||||
|
||||
public void setKo(Integer ko) {
|
||||
this.ko = ko;
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
package io.metersphere.report.dto;
|
||||
|
||||
import io.metersphere.report.base.ErrorsTop5;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ErrorsTop5DTO {
|
||||
|
||||
private List<ErrorsTop5> errorsTop5List;
|
||||
private String label;
|
||||
private String totalSamples;
|
||||
private String totalErrors;
|
||||
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 List<ErrorsTop5> getErrorsTop5List() {
|
||||
return errorsTop5List;
|
||||
}
|
||||
|
||||
public void setErrorsTop5List(List<ErrorsTop5> errorsTop5List) {
|
||||
this.errorsTop5List = errorsTop5List;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getTotalSamples() {
|
||||
return totalSamples;
|
||||
}
|
||||
|
||||
public void setTotalSamples(String totalSamples) {
|
||||
this.totalSamples = totalSamples;
|
||||
}
|
||||
|
||||
public String getTotalErrors() {
|
||||
return totalErrors;
|
||||
}
|
||||
|
||||
public void setTotalErrors(String totalErrors) {
|
||||
this.totalErrors = totalErrors;
|
||||
}
|
||||
|
||||
public String getError1() {
|
||||
return error1;
|
||||
}
|
||||
|
||||
public void setError1(String error1) {
|
||||
this.error1 = error1;
|
||||
}
|
||||
|
||||
public String getError1Size() {
|
||||
return error1Size;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -1,16 +1,12 @@
|
|||
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");
|
||||
|
@ -37,23 +33,29 @@ public class ResultDataParse {
|
|||
ListResultData data = (ListResultData) resultData.getResult("data");
|
||||
int size = data.getSize();
|
||||
String[] strArray = new String[size];
|
||||
if (size > 0) {
|
||||
T t = null;
|
||||
for (int j = 0; j < size; j++) {
|
||||
ValueResultData valueResultData = (ValueResultData) data.get(j);
|
||||
if (valueResultData.getValue() == null) {
|
||||
strArray[j] = "";
|
||||
} else {
|
||||
String accept = valueResultData.accept(new JsonizerVisitor());
|
||||
strArray[j] = accept.replace("\\", "");
|
||||
}
|
||||
Statistics statistics = 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) {
|
||||
|
|
|
@ -13,7 +13,6 @@ import io.metersphere.engine.Engine;
|
|||
import io.metersphere.engine.EngineFactory;
|
||||
import io.metersphere.report.GenerateReport;
|
||||
import io.metersphere.report.base.*;
|
||||
import io.metersphere.report.dto.ErrorsTop5DTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -96,12 +95,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) {
|
||||
|
@ -113,7 +112,6 @@ public class ReportService {
|
|||
}
|
||||
|
||||
public ReportTimeInfo getReportTimeInfo(String id) {
|
||||
checkReportStatus(id);
|
||||
LoadTestReportWithBLOBs loadTestReport = loadTestReportMapper.selectByPrimaryKey(id);
|
||||
String content = loadTestReport.getContent();
|
||||
ReportTimeInfo reportTimeInfo = GenerateReport.getReportTimeInfo(content);
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package io.metersphere;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.opencsv.bean.CsvToBean;
|
||||
import com.opencsv.bean.CsvToBeanBuilder;
|
||||
import com.opencsv.bean.HeaderColumnNameMappingStrategy;
|
||||
import io.metersphere.report.base.RequestStatistics;
|
||||
import org.junit.Test;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
|
@ -201,73 +199,6 @@ public class JtlTest {
|
|||
List<Metric> metrics = beanBuilderExample(jtlString);
|
||||
// 根据label分组,label作为map的key
|
||||
Map<String, List<Metric>> map = metrics.stream().collect(Collectors.groupingBy(Metric::getLabel));
|
||||
getOneRpsResult(map);
|
||||
}
|
||||
|
||||
private void getOneRpsResult(Map<String, List<Metric>> map){
|
||||
Iterator<Map.Entry<String, List<Metric>>> iterator = map.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, List<Metric>> entry = iterator.next();
|
||||
String label = entry.getKey();
|
||||
List<Metric> list = entry.getValue();
|
||||
List<String> timestampList = list.stream().map(Metric::getTimestamp).collect(Collectors.toList());
|
||||
int index=0;
|
||||
//总的响应时间
|
||||
int sumElapsed=0;
|
||||
Integer failSize = 0;
|
||||
Integer totalBytes = 0;
|
||||
// 响应时间的列表排序之后 用于计算90%line、95%line、99line
|
||||
List<Integer> elapsedList = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
try {
|
||||
Metric row = list.get(i);
|
||||
//响应时间
|
||||
String elapsed = row.getElapsed();
|
||||
sumElapsed += Integer.valueOf(elapsed);
|
||||
elapsedList.add(Integer.valueOf(elapsed));
|
||||
//成功与否
|
||||
String success = row.getSuccess();
|
||||
if (!"true".equals(success)){
|
||||
failSize++;
|
||||
}
|
||||
//字节
|
||||
String bytes = row.getBytes();
|
||||
totalBytes += Integer.valueOf(bytes);
|
||||
|
||||
index++;
|
||||
}catch (Exception e){
|
||||
System.out.println("exception i:"+i);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(elapsedList, new Comparator<Integer>() {
|
||||
public int compare(Integer o1, Integer o2) {
|
||||
return o1-o2;
|
||||
}
|
||||
});
|
||||
|
||||
Integer tp90 = elapsedList.size()*9/10;
|
||||
Integer tp95 = elapsedList.size()*95/100;
|
||||
Integer tp99 = elapsedList.size()*99/100;
|
||||
|
||||
Long l = Long.valueOf(timestampList.get(index-1)) - Long.valueOf(timestampList.get(0));
|
||||
|
||||
RequestStatistics sceneResult = new RequestStatistics();
|
||||
sceneResult.setRequestLabel(label);
|
||||
sceneResult.setSamples(index);
|
||||
// sceneResult.setAverage(sumElapsed/index);
|
||||
sceneResult.setTp90(elapsedList.get(tp90)+"");
|
||||
sceneResult.setTp95(elapsedList.get(tp95)+"");
|
||||
sceneResult.setTp99(elapsedList.get(tp99)+"");
|
||||
sceneResult.setMin(elapsedList.get(0)+"");
|
||||
sceneResult.setMax(elapsedList.get(index-1)+"");
|
||||
sceneResult.setErrors(String.format("%.2f",failSize*100.0/index)+"%");
|
||||
sceneResult.setKbPerSec(String.format("%.2f",totalBytes*1.0/1024/(l*1.0/1000)));
|
||||
System.out.println(JSONObject.toJSONString(sceneResult));
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,13 @@
|
|||
</el-tabs>
|
||||
|
||||
</el-card>
|
||||
<el-dialog :title="title" :visible.sync="showTestLogging">
|
||||
<el-tabs type="border-card" :stretch="true">
|
||||
<el-tab-pane v-for="(item, key) in testLogging" :key="key" :label="key" class="logging-content">
|
||||
{{item}}
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
@ -79,15 +86,18 @@
|
|||
startTime: '0',
|
||||
endTime: '0',
|
||||
minutes: '0',
|
||||
seconds: '0'
|
||||
seconds: '0',
|
||||
title: 'Logging',
|
||||
testLogging: null,
|
||||
showTestLogging: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
initBreadcrumb() {
|
||||
if(this.reportId){
|
||||
if (this.reportId) {
|
||||
this.result = this.$get("/performance/report/test/pro/info/" + this.reportId, res => {
|
||||
let data = res.data;
|
||||
if(data){
|
||||
if (data) {
|
||||
this.reportName = data.name;
|
||||
this.testName = data.testName;
|
||||
this.projectName = data.projectName;
|
||||
|
@ -96,10 +106,10 @@
|
|||
}
|
||||
},
|
||||
initReportTimeInfo() {
|
||||
if(this.reportId){
|
||||
if (this.reportId) {
|
||||
this.result = this.$get("/performance/report/content/report_time/" + this.reportId, res => {
|
||||
let data = res.data;
|
||||
if(data){
|
||||
if (data) {
|
||||
this.startTime = data.startTime;
|
||||
this.endTime = data.endTime;
|
||||
let duration = data.duration;
|
||||
|
@ -108,23 +118,37 @@
|
|||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
getLog(testId) {
|
||||
this.result = this.$get('/performance/log/' + testId, response => {
|
||||
this.testLogging = response.data;
|
||||
})
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.reportId = this.$route.path.split('/')[4];
|
||||
this.$get("/performance/report/" + this.reportId, res => {
|
||||
this.result = this.$get("/performance/report/" + this.reportId, res => {
|
||||
let data = res.data;
|
||||
this.status = data.status;
|
||||
if (data.status === "Error") {
|
||||
switch (data.status) {
|
||||
case 'Error':
|
||||
this.$message({
|
||||
type: 'warning',
|
||||
message: "报告生成错误,无法查看!"
|
||||
});
|
||||
} else if (data.status === "Starting") {
|
||||
break;
|
||||
case 'Starting':
|
||||
this.$message({
|
||||
type: 'info',
|
||||
message: "报告生成中...."
|
||||
});
|
||||
break;
|
||||
case 'Running':
|
||||
this.showTestLogging = true;
|
||||
this.getLog(data.testId);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
})
|
||||
this.initBreadcrumb();
|
||||
|
@ -133,10 +157,10 @@
|
|||
watch: {
|
||||
'$route'(to) {
|
||||
let reportId = to.path.split('/')[4];
|
||||
if(reportId){
|
||||
if (reportId) {
|
||||
this.$get("/performance/report/test/pro/info/" + reportId, response => {
|
||||
let data = response.data;
|
||||
if(data){
|
||||
if (data) {
|
||||
this.reportName = data.name;
|
||||
this.testName = data.testName;
|
||||
this.projectName = data.projectName;
|
||||
|
@ -144,7 +168,7 @@
|
|||
});
|
||||
this.result = this.$get("/performance/report/content/report_time/" + this.reportId, res => {
|
||||
let data = res.data;
|
||||
if(data){
|
||||
if (data) {
|
||||
this.startTime = data.startTime;
|
||||
this.endTime = data.endTime;
|
||||
let duration = data.duration;
|
||||
|
@ -170,4 +194,10 @@
|
|||
display: block;
|
||||
color: #5C7878;
|
||||
}
|
||||
|
||||
.logging-content {
|
||||
white-space: pre-line;
|
||||
height: calc(100vh - 450px);
|
||||
overflow: auto;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue