报告测试概览
This commit is contained in:
parent
5f1c561db6
commit
5f162baba2
|
@ -6,14 +6,11 @@ import com.opencsv.bean.HeaderColumnNameMappingStrategy;
|
|||
import io.metersphere.report.base.*;
|
||||
import io.metersphere.report.dto.ErrorsTop5DTO;
|
||||
import io.metersphere.report.dto.RequestStatisticsDTO;
|
||||
import org.apache.bcel.verifier.statics.LONG_Upper;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class JtlResolver {
|
||||
|
@ -22,7 +19,6 @@ public class JtlResolver {
|
|||
HeaderColumnNameMappingStrategy<Metric> ms = new HeaderColumnNameMappingStrategy<>();
|
||||
ms.setType(Metric.class);
|
||||
try (Reader reader = new StringReader(jtlString)) {
|
||||
|
||||
CsvToBean<Metric> cb = new CsvToBeanBuilder<Metric>(reader)
|
||||
.withType(Metric.class)
|
||||
.withSkipLines(0)
|
||||
|
@ -41,36 +37,33 @@ public class JtlResolver {
|
|||
List<RequestStatistics> requestStatisticsList = new ArrayList<>();
|
||||
Iterator<Map.Entry<String, List<Metric>>> iterator = map.entrySet().iterator();
|
||||
List<Integer> allelapse = new ArrayList<>();
|
||||
Integer totalAverage = 0;
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
int totalAverage = 0;
|
||||
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;
|
||||
Float totalBytes = 0f;
|
||||
int failSize = 0;
|
||||
float totalBytes = 0f;
|
||||
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);
|
||||
totalAverage += Integer.valueOf(elapsed);
|
||||
sumElapsed += Integer.parseInt(elapsed);
|
||||
totalAverage += Integer.parseInt(elapsed);
|
||||
elapsedList.add(Integer.valueOf(elapsed));
|
||||
allelapse.add(Integer.valueOf(elapsed));
|
||||
//成功与否
|
||||
String success = row.getSuccess();
|
||||
if (!"true".equals(success)){
|
||||
failSize++;
|
||||
}
|
||||
//字节
|
||||
String bytes = row.getBytes();
|
||||
totalBytes += Float.valueOf(bytes);
|
||||
totalBytes += Float.parseFloat(bytes);
|
||||
index++;
|
||||
}catch (Exception e){
|
||||
System.out.println("exception i:"+i);
|
||||
|
@ -79,17 +72,19 @@ public class JtlResolver {
|
|||
|
||||
Collections.sort(elapsedList);
|
||||
|
||||
Integer tp90 = elapsedList.size()*90/100;
|
||||
Integer tp95 = elapsedList.size()*95/100;
|
||||
Integer tp99 = elapsedList.size()*99/100;
|
||||
Long l = Long.valueOf(timestampList.get(timestampList.size()-1)) - Long.valueOf(timestampList.get(0));
|
||||
int tp90 = elapsedList.size()*90/100;
|
||||
int tp95 = elapsedList.size()*95/100;
|
||||
int tp99 = elapsedList.size()*99/100;
|
||||
long l = Long.valueOf(timestampList.get(timestampList.size()-1)) - Long.valueOf(timestampList.get(0));
|
||||
|
||||
RequestStatistics requestStatistics = new RequestStatistics();
|
||||
requestStatistics.setRequestLabel(label);
|
||||
requestStatistics.setSamples(index);
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
|
||||
|
||||
String s = df.format((float)sumElapsed/index);
|
||||
requestStatistics.setAverage(s+"");
|
||||
|
||||
/**
|
||||
* TP90的计算
|
||||
* 1,把一段时间内全部的请求的响应时间,从小到大排序,获得序列A
|
||||
|
@ -100,6 +95,7 @@ public class JtlResolver {
|
|||
requestStatistics.setTp90(elapsedList.get(tp90)+"");
|
||||
requestStatistics.setTp95(elapsedList.get(tp95)+"");
|
||||
requestStatistics.setTp99(elapsedList.get(tp99)+"");
|
||||
|
||||
requestStatistics.setMin(elapsedList.get(0)+"");
|
||||
requestStatistics.setMax(elapsedList.get(index-1)+"");
|
||||
requestStatistics.setErrors(String.format("%.2f",failSize*100.0/index)+"%");
|
||||
|
@ -113,16 +109,15 @@ public class JtlResolver {
|
|||
}
|
||||
Collections.sort(allelapse);
|
||||
|
||||
Integer totalTP90 = allelapse.size()*90/100;
|
||||
Integer totalTP95 = allelapse.size()*95/100;
|
||||
Integer totalTP99 = allelapse.size()*99/100;
|
||||
int totalTP90 = allelapse.size()*90/100;
|
||||
int totalTP95 = allelapse.size()*95/100;
|
||||
int totalTP99 = allelapse.size()*99/100;
|
||||
|
||||
Integer min = allelapse.get(0);
|
||||
Integer max = allelapse.get(allelapse.size() - 1);
|
||||
|
||||
Integer allSamples = requestStatisticsList.stream().mapToInt(RequestStatistics::getSamples).sum();
|
||||
Integer failSize = requestStatisticsList.stream().mapToInt(RequestStatistics::getKo).sum();
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
int allSamples = requestStatisticsList.stream().mapToInt(RequestStatistics::getSamples).sum();
|
||||
int failSize = requestStatisticsList.stream().mapToInt(RequestStatistics::getKo).sum();
|
||||
double errors = (double)failSize / allSamples * 100;
|
||||
String totalerrors = df.format(errors);
|
||||
double average = (double)totalAverage / allSamples;
|
||||
|
@ -157,6 +152,7 @@ public class JtlResolver {
|
|||
List<Errors> errorsList = new ArrayList<>();
|
||||
Map<String, List<Metric>> collect = falseList.stream().collect(Collectors.groupingBy(JtlResolver::getResponseCodeAndFailureMessage));
|
||||
Iterator<Map.Entry<String, List<Metric>>> iterator = collect.entrySet().iterator();
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, List<Metric>> next = iterator.next();
|
||||
String key = next.getKey();
|
||||
|
@ -164,10 +160,9 @@ public class JtlResolver {
|
|||
Errors errors = new Errors();
|
||||
errors.setErrorType(key);
|
||||
errors.setErrorNumber(String.valueOf(value.size()));
|
||||
Integer errorSize = value.size();
|
||||
Integer errorAllSize = falseList.size();
|
||||
Integer allSamples = totalLines.size();
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
int errorSize = value.size();
|
||||
int errorAllSize = falseList.size();
|
||||
int allSamples = totalLines.size();
|
||||
errors.setPrecentOfErrors(df.format((double)errorSize / errorAllSize * 100) + "%");
|
||||
errors.setPrecentOfAllSamples(df.format((double)errorSize / allSamples * 100) + "%");
|
||||
errorsList.add(errors);
|
||||
|
@ -202,7 +197,7 @@ public class JtlResolver {
|
|||
errorsTop5s.add(errorsTop5);
|
||||
}
|
||||
|
||||
Collections.sort(errorsTop5s, (t0, t1) -> t1.getErrorsAllSize().compareTo(t0.getErrorsAllSize()));
|
||||
errorsTop5s.sort((t0, t1) -> t1.getErrorsAllSize().compareTo(t0.getErrorsAllSize()));
|
||||
|
||||
if (errorsTop5s.size() >= 5) {
|
||||
errorsTop5s = errorsTop5s.subList(0, 5);
|
||||
|
@ -212,7 +207,7 @@ public class JtlResolver {
|
|||
top5DTO.setErrorsTop5List(errorsTop5s);
|
||||
top5DTO.setTotalSamples(String.valueOf(totalLines.size()));
|
||||
top5DTO.setTotalErrors(String.valueOf(falseList.size()));
|
||||
Integer size = errorsTop5s.size();
|
||||
int size = errorsTop5s.size();
|
||||
// Total行 信息
|
||||
top5DTO.setError1(size > 0 ? errorsTop5s.get(0).getError() : null);
|
||||
top5DTO.setError1Size(size > 0 ? errorsTop5s.get(0).getErrors() : null);
|
||||
|
@ -234,8 +229,9 @@ public class JtlResolver {
|
|||
List<Metric> total = JtlResolver.resolver(jtlString);
|
||||
Map<String, List<Metric>> collect = total.stream().collect(Collectors.groupingBy(Metric::getTimestamp));
|
||||
Iterator<Map.Entry<String, List<Metric>>> iterator = collect.entrySet().iterator();
|
||||
Integer max = 0;
|
||||
Integer totalElapsed = 0;
|
||||
int max = 0;
|
||||
int totalElapsed = 0;
|
||||
float totalBytes = 0f;
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, List<Metric>> entry = iterator.next();
|
||||
List<Metric> list = entry.getValue();
|
||||
|
@ -245,27 +241,38 @@ public class JtlResolver {
|
|||
for (int i = 0; i < list.size(); i++) {
|
||||
Metric metric = list.get(i);
|
||||
String elapsed = metric.getElapsed();
|
||||
totalElapsed += Integer.valueOf(elapsed);
|
||||
totalElapsed += Integer.parseInt(elapsed);
|
||||
String bytes = metric.getBytes();
|
||||
totalBytes += Float.parseFloat(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(total, Comparator.comparing(t0 -> Long.valueOf(t0.getTimestamp())));
|
||||
Long timestamp1 = Long.valueOf(total.get(0).getTimestamp());
|
||||
Long timestamp2 = Long.valueOf(total.get(total.size()-1).getTimestamp());
|
||||
Long seconds = (timestamp2 - timestamp1) / 1000;
|
||||
total.sort(Comparator.comparing(t0 -> Long.valueOf(t0.getTimestamp())));
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
double avgThroughput = (double)total.size() / seconds;
|
||||
|
||||
List<Metric> falseList = total.stream().filter(metric -> StringUtils.equals("false", metric.getSuccess())).collect(Collectors.toList());
|
||||
double errors = (double)falseList.size() / total.size() * 100;
|
||||
|
||||
testOverview.setMaxUsers(String.valueOf(max));
|
||||
|
||||
List<Metric> list90 = total.subList(0, total.size() * 9 / 10);
|
||||
long sum = list90.stream().mapToLong(metric -> Long.parseLong(metric.getElapsed())).sum();
|
||||
double avg90 = (double)sum / 1000 / list90.size();
|
||||
testOverview.setResponseTime90(df.format(avg90));
|
||||
|
||||
Long timestamp1 = Long.valueOf(total.get(0).getTimestamp());
|
||||
Long timestamp2 = Long.valueOf(total.get(total.size()-1).getTimestamp());
|
||||
long seconds = (timestamp2 - timestamp1) / 1000;
|
||||
double avgThroughput = (double)total.size() / seconds;
|
||||
testOverview.setAvgThroughput(df.format(avgThroughput));
|
||||
|
||||
List<Metric> falseList = total.stream().filter(metric -> StringUtils.equals("false", metric.getSuccess())).collect(Collectors.toList());
|
||||
double errors = falseList.size() * 1.0 / total.size() * 100;
|
||||
testOverview.setErrors(df.format(errors));
|
||||
double avg = (double)totalElapsed / total.size() / 1000; // s
|
||||
|
||||
double avg = totalElapsed * 1.0 / total.size() / 1000; // s
|
||||
testOverview.setAvgResponseTime(df.format(avg));
|
||||
// testOverview.setResponseTime90();
|
||||
// testOverview.setAvgBandwidth();
|
||||
|
||||
double bandwidth = totalBytes * 1.0 / 1024 / seconds;
|
||||
testOverview.setAvgBandwidth(df.format(bandwidth));
|
||||
|
||||
return testOverview;
|
||||
}
|
||||
|
||||
|
|
|
@ -161,8 +161,8 @@
|
|||
this.avgThroughput = data.avgThroughput;
|
||||
this.errors = data.errors;
|
||||
this.avgResponseTime = data.avgResponseTime;
|
||||
// this.responseTime90 = data.responseTime90;
|
||||
// this.avgBandwidth = data.avgBandwidth;
|
||||
this.responseTime90 = data.responseTime90;
|
||||
this.avgBandwidth = data.avgBandwidth;
|
||||
})
|
||||
}
|
||||
},
|
||||
|
@ -181,8 +181,8 @@
|
|||
this.avgThroughput = data.avgThroughput;
|
||||
this.errors = data.errors;
|
||||
this.avgResponseTime = data.avgResponseTime;
|
||||
// this.responseTime90 = data.responseTime90;
|
||||
// this.avgBandwidth = data.avgBandwidth;
|
||||
this.responseTime90 = data.responseTime90;
|
||||
this.avgBandwidth = data.avgBandwidth;
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue