Merge branch 'dev' of https://github.com/fit2cloudrd/metersphere-server into dev
This commit is contained in:
commit
c6479e7183
|
@ -11,8 +11,6 @@ public class LoadTest implements Serializable {
|
|||
|
||||
private String description;
|
||||
|
||||
private String scenarioDefinition;
|
||||
|
||||
private Long createTime;
|
||||
|
||||
private Long updateTime;
|
||||
|
@ -55,14 +53,6 @@ public class LoadTest implements Serializable {
|
|||
this.description = description == null ? null : description.trim();
|
||||
}
|
||||
|
||||
public String getScenarioDefinition() {
|
||||
return scenarioDefinition;
|
||||
}
|
||||
|
||||
public void setScenarioDefinition(String scenarioDefinition) {
|
||||
this.scenarioDefinition = scenarioDefinition == null ? null : scenarioDefinition.trim();
|
||||
}
|
||||
|
||||
public Long getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
|
|
@ -384,76 +384,6 @@ public class LoadTestExample {
|
|||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionIsNull() {
|
||||
addCriterion("scenario_definition is null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionIsNotNull() {
|
||||
addCriterion("scenario_definition is not null");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionEqualTo(String value) {
|
||||
addCriterion("scenario_definition =", value, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionNotEqualTo(String value) {
|
||||
addCriterion("scenario_definition <>", value, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionGreaterThan(String value) {
|
||||
addCriterion("scenario_definition >", value, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionGreaterThanOrEqualTo(String value) {
|
||||
addCriterion("scenario_definition >=", value, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionLessThan(String value) {
|
||||
addCriterion("scenario_definition <", value, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionLessThanOrEqualTo(String value) {
|
||||
addCriterion("scenario_definition <=", value, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionLike(String value) {
|
||||
addCriterion("scenario_definition like", value, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionNotLike(String value) {
|
||||
addCriterion("scenario_definition not like", value, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionIn(List<String> values) {
|
||||
addCriterion("scenario_definition in", values, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionNotIn(List<String> values) {
|
||||
addCriterion("scenario_definition not in", values, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionBetween(String value1, String value2) {
|
||||
addCriterion("scenario_definition between", value1, value2, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andScenarioDefinitionNotBetween(String value1, String value2) {
|
||||
addCriterion("scenario_definition not between", value1, value2, "scenarioDefinition");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andCreateTimeIsNull() {
|
||||
addCriterion("create_time is null");
|
||||
return (Criteria) this;
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
<result column="project_id" jdbcType="VARCHAR" property="projectId" />
|
||||
<result column="name" jdbcType="VARCHAR" property="name" />
|
||||
<result column="description" jdbcType="VARCHAR" property="description" />
|
||||
<result column="scenario_definition" jdbcType="VARCHAR" property="scenarioDefinition" />
|
||||
<result column="create_time" jdbcType="BIGINT" property="createTime" />
|
||||
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
|
||||
<result column="status" jdbcType="VARCHAR" property="status" />
|
||||
|
@ -76,8 +75,7 @@
|
|||
</where>
|
||||
</sql>
|
||||
<sql id="Base_Column_List">
|
||||
id, project_id, name, description, scenario_definition, create_time, update_time,
|
||||
status, test_resource_pool_id
|
||||
id, project_id, name, description, create_time, update_time, status, test_resource_pool_id
|
||||
</sql>
|
||||
<sql id="Blob_Column_List">
|
||||
load_configuration, advanced_configuration, schedule
|
||||
|
@ -132,15 +130,15 @@
|
|||
</delete>
|
||||
<insert id="insert" parameterType="io.metersphere.base.domain.LoadTestWithBLOBs">
|
||||
insert into load_test (id, project_id, name,
|
||||
description, scenario_definition, create_time,
|
||||
update_time, status, test_resource_pool_id,
|
||||
load_configuration, advanced_configuration,
|
||||
schedule)
|
||||
description, create_time, update_time,
|
||||
status, test_resource_pool_id, load_configuration,
|
||||
advanced_configuration, schedule
|
||||
)
|
||||
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
|
||||
#{description,jdbcType=VARCHAR}, #{scenarioDefinition,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
|
||||
#{updateTime,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR},
|
||||
#{loadConfiguration,jdbcType=LONGVARCHAR}, #{advancedConfiguration,jdbcType=LONGVARCHAR},
|
||||
#{schedule,jdbcType=LONGVARCHAR})
|
||||
#{description,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
|
||||
#{status,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR}, #{loadConfiguration,jdbcType=LONGVARCHAR},
|
||||
#{advancedConfiguration,jdbcType=LONGVARCHAR}, #{schedule,jdbcType=LONGVARCHAR}
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestWithBLOBs">
|
||||
insert into load_test
|
||||
|
@ -157,9 +155,6 @@
|
|||
<if test="description != null">
|
||||
description,
|
||||
</if>
|
||||
<if test="scenarioDefinition != null">
|
||||
scenario_definition,
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time,
|
||||
</if>
|
||||
|
@ -195,9 +190,6 @@
|
|||
<if test="description != null">
|
||||
#{description,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="scenarioDefinition != null">
|
||||
#{scenarioDefinition,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
#{createTime,jdbcType=BIGINT},
|
||||
</if>
|
||||
|
@ -242,9 +234,6 @@
|
|||
<if test="record.description != null">
|
||||
description = #{record.description,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.scenarioDefinition != null">
|
||||
scenario_definition = #{record.scenarioDefinition,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="record.createTime != null">
|
||||
create_time = #{record.createTime,jdbcType=BIGINT},
|
||||
</if>
|
||||
|
@ -277,7 +266,6 @@
|
|||
project_id = #{record.projectId,jdbcType=VARCHAR},
|
||||
name = #{record.name,jdbcType=VARCHAR},
|
||||
description = #{record.description,jdbcType=VARCHAR},
|
||||
scenario_definition = #{record.scenarioDefinition,jdbcType=VARCHAR},
|
||||
create_time = #{record.createTime,jdbcType=BIGINT},
|
||||
update_time = #{record.updateTime,jdbcType=BIGINT},
|
||||
status = #{record.status,jdbcType=VARCHAR},
|
||||
|
@ -295,7 +283,6 @@
|
|||
project_id = #{record.projectId,jdbcType=VARCHAR},
|
||||
name = #{record.name,jdbcType=VARCHAR},
|
||||
description = #{record.description,jdbcType=VARCHAR},
|
||||
scenario_definition = #{record.scenarioDefinition,jdbcType=VARCHAR},
|
||||
create_time = #{record.createTime,jdbcType=BIGINT},
|
||||
update_time = #{record.updateTime,jdbcType=BIGINT},
|
||||
status = #{record.status,jdbcType=VARCHAR},
|
||||
|
@ -316,9 +303,6 @@
|
|||
<if test="description != null">
|
||||
description = #{description,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="scenarioDefinition != null">
|
||||
scenario_definition = #{scenarioDefinition,jdbcType=VARCHAR},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime,jdbcType=BIGINT},
|
||||
</if>
|
||||
|
@ -348,7 +332,6 @@
|
|||
set project_id = #{projectId,jdbcType=VARCHAR},
|
||||
name = #{name,jdbcType=VARCHAR},
|
||||
description = #{description,jdbcType=VARCHAR},
|
||||
scenario_definition = #{scenarioDefinition,jdbcType=VARCHAR},
|
||||
create_time = #{createTime,jdbcType=BIGINT},
|
||||
update_time = #{updateTime,jdbcType=BIGINT},
|
||||
status = #{status,jdbcType=VARCHAR},
|
||||
|
@ -363,7 +346,6 @@
|
|||
set project_id = #{projectId,jdbcType=VARCHAR},
|
||||
name = #{name,jdbcType=VARCHAR},
|
||||
description = #{description,jdbcType=VARCHAR},
|
||||
scenario_definition = #{scenarioDefinition,jdbcType=VARCHAR},
|
||||
create_time = #{createTime,jdbcType=BIGINT},
|
||||
update_time = #{updateTime,jdbcType=BIGINT},
|
||||
status = #{status,jdbcType=VARCHAR},
|
||||
|
|
|
@ -19,10 +19,16 @@
|
|||
select ltr.id, ltr.name, ltr.test_id as testId, ltr.description,
|
||||
ltr.create_time as createTime, ltr.update_time as updateTime, ltr.status as status, lt.name as testName
|
||||
from load_test_report ltr join load_test lt on ltr.test_id = lt.id
|
||||
<if test="reportRequest.workspaceId != null">
|
||||
JOIN project on project.id = lt.project_id
|
||||
</if>
|
||||
<where>
|
||||
<if test="reportRequest.name != null">
|
||||
AND ltr.name like CONCAT('%', #{reportRequest.name},'%')
|
||||
</if>
|
||||
<if test="reportRequest.workspaceId != null">
|
||||
AND workspace_id = #{reportRequest.workspaceId,jdbcType=VARCHAR}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY ltr.update_time DESC
|
||||
</select>
|
||||
|
|
|
@ -27,7 +27,7 @@ public class PerformanceReportController {
|
|||
|
||||
@GetMapping("/recent/{count}")
|
||||
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
|
||||
public List<LoadTestReport> recentProjects(@PathVariable int count) {
|
||||
public List<ReportDTO> recentProjects(@PathVariable int count) {
|
||||
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
|
||||
ReportRequest request = new ReportRequest();
|
||||
request.setWorkspaceId(currentWorkspaceId);
|
||||
|
@ -38,6 +38,8 @@ public class PerformanceReportController {
|
|||
|
||||
@PostMapping("/list/all/{goPage}/{pageSize}")
|
||||
public Pager<List<ReportDTO>> getReportList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ReportRequest request) {
|
||||
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
|
||||
request.setWorkspaceId(currentWorkspaceId);
|
||||
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
|
||||
return PageUtils.setPageInfo(page, reportService.getReportList(request));
|
||||
}
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
package io.metersphere.report;
|
||||
|
||||
import com.opencsv.bean.CsvToBean;
|
||||
import com.opencsv.bean.CsvToBeanBuilder;
|
||||
import com.opencsv.bean.HeaderColumnNameMappingStrategy;
|
||||
import io.metersphere.report.base.*;
|
||||
import io.metersphere.report.parse.ResultDataParse;
|
||||
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.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
public class GenerateReport {
|
||||
|
||||
private static List<Metric> resolver(String jtlString) {
|
||||
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)
|
||||
.withMappingStrategy(ms)
|
||||
.withIgnoreLeadingWhiteSpace(true)
|
||||
.build();
|
||||
return cb.parse();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<Errors> getErrorsList(String jtlString) {
|
||||
Map<String, Object> statisticsDataMap = ResultDataParse.getSummryDataMap(jtlString, new ErrorsSummaryConsumer());
|
||||
return ResultDataParse.summaryMapParsing(statisticsDataMap, Errors.class);
|
||||
}
|
||||
|
||||
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, Statistics.class);
|
||||
}
|
||||
|
||||
public static TestOverview getTestOverview(String jtlString) {
|
||||
DecimalFormat decimalFormat = new DecimalFormat("0.00");
|
||||
|
||||
Map<String, Object> activeDataMap = ResultDataParse.getGraphDataMap(jtlString, new ActiveThreadsGraphConsumer());
|
||||
List<ChartsData> usersList = ResultDataParse.graphMapParsing(activeDataMap, "users");
|
||||
Optional<ChartsData> max = usersList.stream().max(Comparator.comparing(ChartsData::getyAxis));
|
||||
int maxUser = max.get().getyAxis().setScale(0, BigDecimal.ROUND_UP).intValue();
|
||||
|
||||
Map<String, Object> hitsDataMap = ResultDataParse.getGraphDataMap(jtlString, new HitsPerSecondGraphConsumer());
|
||||
List<ChartsData> hitsList = ResultDataParse.graphMapParsing(hitsDataMap, "hits");
|
||||
double hits = hitsList.stream().map(ChartsData::getyAxis)
|
||||
.mapToDouble(BigDecimal::doubleValue)
|
||||
.average().orElse(0);
|
||||
|
||||
Map<String, Object> errorDataMap = ResultDataParse.getSummryDataMap(jtlString, new StatisticsSummaryConsumer());
|
||||
List<Statistics> statisticsList = ResultDataParse.summaryMapParsing(errorDataMap, Statistics.class);
|
||||
Optional<Double> error = statisticsList.stream().map(item -> Double.parseDouble(item.getError())).reduce(Double::sum);
|
||||
double avgTp90 = statisticsList.stream().map(item -> Double.parseDouble(item.getTp90())).mapToDouble(Double::doubleValue).average().orElse(0);
|
||||
double avgBandwidth = statisticsList.stream().map(item -> Double.parseDouble(item.getReceived())).mapToDouble(Double::doubleValue).average().orElse(0);
|
||||
|
||||
Map<String, Object> responseDataMap = ResultDataParse.getGraphDataMap(jtlString, new ResponseTimeOverTimeGraphConsumer());
|
||||
List<ChartsData> responseDataList = ResultDataParse.graphMapParsing(responseDataMap, "response");
|
||||
double responseTime = responseDataList.stream().map(ChartsData::getyAxis)
|
||||
.mapToDouble(BigDecimal::doubleValue)
|
||||
.average().orElse(0);
|
||||
|
||||
TestOverview testOverview = new TestOverview();
|
||||
testOverview.setMaxUsers(String.valueOf(maxUser));
|
||||
testOverview.setAvgThroughput(decimalFormat.format(hits));
|
||||
testOverview.setErrors(decimalFormat.format(error.get()));
|
||||
testOverview.setAvgResponseTime(decimalFormat.format(responseTime / 1000));
|
||||
testOverview.setResponseTime90(decimalFormat.format(avgTp90 / 1000));
|
||||
testOverview.setAvgBandwidth(decimalFormat.format(avgBandwidth));
|
||||
return testOverview;
|
||||
}
|
||||
|
||||
public static List<ChartsData> getLoadChartData(String jtlString) {
|
||||
Map<String, Object> activeThreadMap = ResultDataParse.getGraphDataMap(jtlString, new ActiveThreadsGraphConsumer());
|
||||
Map<String, Object> hitsMap = ResultDataParse.getGraphDataMap(jtlString, new HitsPerSecondGraphConsumer());
|
||||
List<ChartsData> resultList = ResultDataParse.graphMapParsing(activeThreadMap, "users");
|
||||
List<ChartsData> hitsList = ResultDataParse.graphMapParsing(hitsMap, "hits");
|
||||
resultList.addAll(hitsList);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
public static List<ChartsData> getResponseTimeChartData(String jtlString) {
|
||||
Map<String, Object> activeThreadMap = ResultDataParse.getGraphDataMap(jtlString, new ActiveThreadsGraphConsumer());
|
||||
Map<String, Object> responseTimeMap = ResultDataParse.getGraphDataMap(jtlString, new ResponseTimeOverTimeGraphConsumer());
|
||||
List<ChartsData> resultList = ResultDataParse.graphMapParsing(activeThreadMap, "users");
|
||||
List<ChartsData> responseTimeList = ResultDataParse.graphMapParsing(responseTimeMap, "responseTime");
|
||||
resultList.addAll(responseTimeList);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
public static ReportTimeInfo getReportTimeInfo(String jtlString) {
|
||||
List<Metric> totalLineList = GenerateReport.resolver(jtlString);
|
||||
|
||||
totalLineList.sort(Comparator.comparing(t0 -> Long.valueOf(t0.getTimestamp())));
|
||||
|
||||
String startTimeStamp = totalLineList.get(0).getTimestamp();
|
||||
String endTimeStamp = totalLineList.get(totalLineList.size() - 1).getTimestamp();
|
||||
|
||||
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()));
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
package io.metersphere.report.parse;
|
||||
|
||||
import io.metersphere.commons.utils.MsJMeterUtils;
|
||||
import io.metersphere.report.base.ChartsData;
|
||||
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;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
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 <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");
|
||||
if (items.getSize() > 0) {
|
||||
for (int i = 0; i < items.getSize(); i++) {
|
||||
MapResultData resultData = (MapResultData) items.get(i);
|
||||
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("\\", "");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
t = setParam(clazz, strArray);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
list.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<ChartsData> graphMapParsing(Map<String, Object> map, String seriesName) {
|
||||
List<ChartsData> list = new ArrayList<>();
|
||||
// ThreadGroup
|
||||
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) {
|
||||
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);
|
||||
String result = listResultData.accept(new JsonizerVisitor());
|
||||
result = result.substring(1, result.length() - 1);
|
||||
String[] split = result.split(",");
|
||||
ChartsData chartsData = new ChartsData();
|
||||
BigDecimal bigDecimal = new BigDecimal(split[0]);
|
||||
String timeStamp = bigDecimal.toPlainString();
|
||||
String time = null;
|
||||
try {
|
||||
time = formatDate(stampToDate(DATE_TIME_PATTERN, timeStamp));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static Map<String, Object> getGraphDataMap(String jtlString, AbstractOverTimeGraphConsumer timeGraphConsumer) {
|
||||
AbstractOverTimeGraphConsumer abstractOverTimeGraphConsumer = timeGraphConsumer;
|
||||
abstractOverTimeGraphConsumer.setGranularity(60000);
|
||||
abstractOverTimeGraphConsumer.initialize();
|
||||
SampleContext sampleContext = initJmeterConsumer(jtlString, abstractOverTimeGraphConsumer);
|
||||
return sampleContext.getData();
|
||||
}
|
||||
|
||||
public static Map<String, Object> getSummryDataMap(String jtlString, AbstractSummaryConsumer<?> summaryConsumer) {
|
||||
AbstractSummaryConsumer<?> abstractSummaryConsumer = summaryConsumer;
|
||||
SampleContext sampleContext = initJmeterConsumer(jtlString, summaryConsumer);
|
||||
return sampleContext.getData();
|
||||
}
|
||||
|
||||
private static SampleContext initJmeterConsumer(String jtlString, AbstractSampleConsumer abstractSampleConsumer) {
|
||||
int row = 0;
|
||||
// 使用反射获取properties
|
||||
MsJMeterUtils.loadJMeterProperties("jmeter.properties");
|
||||
SampleMetadata sampleMetaData = createTestMetaData();
|
||||
SampleContext sampleContext = new SampleContext();
|
||||
abstractSampleConsumer.setSampleContext(sampleContext);
|
||||
abstractSampleConsumer.startConsuming();
|
||||
StringTokenizer tokenizer = new StringTokenizer(jtlString, "\n");
|
||||
// 去掉第一行
|
||||
tokenizer.nextToken();
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
String line = tokenizer.nextToken();
|
||||
String[] data = line.split(",", -1);
|
||||
Sample sample = new Sample(row++, sampleMetaData, data);
|
||||
abstractSampleConsumer.consume(sample, 0);
|
||||
}
|
||||
abstractSampleConsumer.stopConsuming();
|
||||
return sampleContext;
|
||||
}
|
||||
|
||||
// Create a static SampleMetadataObject
|
||||
private static SampleMetadata createTestMetaData() {
|
||||
String columnsString = "timeStamp,elapsed,label,responseCode,responseMessage,threadName,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect";
|
||||
columnsString = "timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect";
|
||||
|
||||
String[] columns = new String[17];
|
||||
int lastComa = 0;
|
||||
int columnIndex = 0;
|
||||
for (int i = 0; i < columnsString.length(); i++) {
|
||||
if (columnsString.charAt(i) == ',') {
|
||||
columns[columnIndex] = columnsString.substring(lastComa, i);
|
||||
lastComa = i + 1;
|
||||
columnIndex++;
|
||||
} else if (i + 1 == columnsString.length()) {
|
||||
columns[columnIndex] = columnsString.substring(lastComa, i + 1);
|
||||
}
|
||||
}
|
||||
return new SampleMetadata(',', columns);
|
||||
}
|
||||
|
||||
private static String stampToDate(String pattern, String timeStamp) {
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
|
||||
LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(timeStamp)), ZoneId.systemDefault());
|
||||
return localDateTime.format(dateTimeFormatter);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
private static <T> T setParam(Class<T> clazz, Object[] args)
|
||||
throws Exception {
|
||||
if (clazz == null || args == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
T t = clazz.newInstance();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
if (fields == null || fields.length > args.length) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
fields[i].setAccessible(true);
|
||||
fields[i].set(t, args[i]);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
}
|
|
@ -35,13 +35,8 @@ public class ReportService {
|
|||
@Resource
|
||||
private LoadTestReportResultMapper loadTestReportResultMapper;
|
||||
|
||||
public List<LoadTestReport> getRecentReportList(ReportRequest request) {
|
||||
LoadTestReportExample example = new LoadTestReportExample();
|
||||
LoadTestReportExample.Criteria criteria = example.createCriteria();
|
||||
//
|
||||
|
||||
example.setOrderByClause("update_time desc");
|
||||
return loadTestReportMapper.selectByExample(example);
|
||||
public List<ReportDTO> getRecentReportList(ReportRequest request) {
|
||||
return extLoadTestReportMapper.getReportList(request);
|
||||
}
|
||||
|
||||
public List<ReportDTO> getReportList(ReportRequest request) {
|
||||
|
@ -88,7 +83,11 @@ public class ReportService {
|
|||
private String getContent(String id, ReportKeys reportKey) {
|
||||
LoadTestReportResultExample example = new LoadTestReportResultExample();
|
||||
example.createCriteria().andReportIdEqualTo(id).andReportKeyEqualTo(reportKey.name());
|
||||
return loadTestReportResultMapper.selectByExampleWithBLOBs(example).get(0).getReportValue();
|
||||
List<LoadTestReportResult> loadTestReportResults = loadTestReportResultMapper.selectByExampleWithBLOBs(example);
|
||||
if (loadTestReportResults.size() != 1) {
|
||||
MSException.throwException("get report result error.");
|
||||
}
|
||||
return loadTestReportResults.get(0).getReportValue();
|
||||
}
|
||||
|
||||
public List<Statistics> getReport(String id) {
|
||||
|
|
|
@ -25,7 +25,6 @@ CREATE TABLE IF NOT EXISTS `load_test` (
|
|||
`project_id` varchar(50) NOT NULL COMMENT 'Project ID this test belongs to',
|
||||
`name` varchar(64) NOT NULL COMMENT 'Test name',
|
||||
`description` varchar(255) DEFAULT NULL COMMENT 'Test description',
|
||||
`scenario_definition` varchar(255) DEFAULT NULL COMMENT 'Scenario definition (JSON format)',
|
||||
`load_configuration` longtext COMMENT 'Load configuration (JSON format)',
|
||||
`advanced_configuration` longtext COMMENT 'Load configuration (JSON format)',
|
||||
`schedule` longtext COMMENT 'Test schedule (cron list)',
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
<el-tag size="mini" type="success" v-else-if="row.status === 'Running'">
|
||||
{{ row.status }}
|
||||
</el-tag>
|
||||
<el-tag size="mini" type="success" v-else-if="row.status === 'Reporting'">
|
||||
<el-tag size="mini" type="warning" v-else-if="row.status === 'Reporting'">
|
||||
{{ row.status }}
|
||||
</el-tag>
|
||||
<el-tag size="mini" type="info" v-else-if="row.status === 'Completed'">
|
||||
|
|
|
@ -55,7 +55,7 @@
|
|||
<el-tag size="mini" type="success" v-else-if="row.status === 'Running'">
|
||||
{{ row.status }}
|
||||
</el-tag>
|
||||
<el-tag size="mini" type="success" v-else-if="row.status === 'Reporting'">
|
||||
<el-tag size="mini" type="warning" v-else-if="row.status === 'Reporting'">
|
||||
{{ row.status }}
|
||||
</el-tag>
|
||||
<el-tag size="mini" type="info" v-else-if="row.status === 'Completed'">
|
||||
|
|
Loading…
Reference in New Issue