csv 解析
This commit is contained in:
parent
34fe47c1bc
commit
bbdb987b64
|
@ -152,24 +152,12 @@
|
|||
<artifactId>jmeter-plugins-casutg</artifactId>
|
||||
<version>2.9</version>
|
||||
</dependency>
|
||||
<!-- jmeter graph -->
|
||||
<dependency>
|
||||
<groupId>kg.apc</groupId>
|
||||
<artifactId>jmeter-plugins-cmd</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>kg.apc</groupId>
|
||||
<artifactId>jmeter-plugins-synthesis</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/kg.apc/jmeter-plugins-standard -->
|
||||
<dependency>
|
||||
<groupId>kg.apc</groupId>
|
||||
<artifactId>jmeter-plugins-standard</artifactId>
|
||||
<version>1.4.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.opencsv</groupId>
|
||||
<artifactId>opencsv</artifactId>
|
||||
<version>5.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
|
|
|
@ -1,41 +1,45 @@
|
|||
package io.metersphere;
|
||||
|
||||
import io.metersphere.commons.constants.JmeterReportType;
|
||||
import kg.apc.jmeter.PluginsCMDWorker;
|
||||
import org.apache.jmeter.util.JMeterUtils;
|
||||
import com.opencsv.bean.CsvToBean;
|
||||
import com.opencsv.bean.CsvToBeanBuilder;
|
||||
import com.opencsv.bean.HeaderColumnNameMappingStrategy;
|
||||
import com.opencsv.bean.MappingStrategy;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Reader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public class GenerateGraphTest {
|
||||
|
||||
/*
|
||||
AggregateReport = JMeter's native Aggregate Report, can be saved only as CSV
|
||||
SynthesisReport = mix between JMeter's native Summary Report and Aggregate Report, can be saved only as CSV
|
||||
ThreadsStateOverTime = Active Threads Over Time
|
||||
BytesThroughputOverTime
|
||||
HitsPerSecond
|
||||
LatenciesOverTime
|
||||
PerfMon = PerfMon Metrics Collector
|
||||
DbMon = DbMon Metrics Collector, DataBase, get performance counters via sql
|
||||
JMXMon = JMXMon Metrics Collector, Java Management Extensions counters
|
||||
ResponseCodesPerSecond
|
||||
ResponseTimesDistribution
|
||||
ResponseTimesOverTime
|
||||
ResponseTimesPercentiles
|
||||
ThroughputVsThreads
|
||||
TimesVsThreads = Response Times VS Threads
|
||||
TransactionsPerSecond
|
||||
PageDataExtractorOverTime
|
||||
MergeResults = MergeResults Command Line Merge Tool to simplify the comparison of two or more load tests, need properties file (like merge-results.properties)
|
||||
*/
|
||||
|
||||
@Test
|
||||
public void test1() {
|
||||
JMeterUtils.setJMeterHome("/opt/fit2cloud/apache-jmeter-5.2.1");
|
||||
JMeterUtils.loadJMeterProperties("/opt/fit2cloud/apache-jmeter-5.2.1/bin/jmeter.properties");
|
||||
PluginsCMDWorker worker = new PluginsCMDWorker();
|
||||
worker.setPluginType(JmeterReportType.AggregateReport.name());
|
||||
worker.addExportMode(2);
|
||||
worker.setOutputCSVFile("/tmp/test0320.csv");
|
||||
worker.setInputFile("/Users/liuruibin/Desktop/0316.jtl");
|
||||
worker.doJob();
|
||||
File csvFile = new File("/Users/liuruibin/Desktop/0316.jtl");
|
||||
HeaderColumnNameMappingStrategy<Metric> ms = new HeaderColumnNameMappingStrategy<>();
|
||||
ms.setType(Metric.class);
|
||||
List<Metric> metrics = beanBuilderExample(csvFile.toPath(), ms);
|
||||
metrics.forEach(c -> {
|
||||
System.out.println(c.getTimestamp());
|
||||
});
|
||||
}
|
||||
|
||||
public static List<Metric> beanBuilderExample(Path path, MappingStrategy<Metric> ms) {
|
||||
try (Reader reader = Files.newBufferedReader(path)) {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,180 @@
|
|||
package io.metersphere;
|
||||
|
||||
import com.opencsv.bean.CsvBindByName;
|
||||
|
||||
public class Metric {
|
||||
// timestamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
|
||||
|
||||
@CsvBindByName(column = "timestamp")
|
||||
private String timestamp;
|
||||
@CsvBindByName(column = "elapsed")
|
||||
private String elapsed;
|
||||
@CsvBindByName(column = "label")
|
||||
private String label;
|
||||
@CsvBindByName(column = "responseCode")
|
||||
private String responseCode;
|
||||
@CsvBindByName(column = "responseMessage")
|
||||
private String responseMessage;
|
||||
@CsvBindByName(column = "threadName")
|
||||
private String threadName;
|
||||
@CsvBindByName(column = "dataType")
|
||||
private String dataType;
|
||||
@CsvBindByName(column = "success")
|
||||
private String success;
|
||||
@CsvBindByName(column = "failureMessage")
|
||||
private String failureMessage;
|
||||
@CsvBindByName(column = "bytes")
|
||||
private String bytes;
|
||||
@CsvBindByName(column = "sentBytes")
|
||||
private String sentBytes;
|
||||
@CsvBindByName(column = "grpThreads")
|
||||
private String grpThreads;
|
||||
@CsvBindByName(column = "allThreads")
|
||||
private String allThreads;
|
||||
@CsvBindByName(column = "URL")
|
||||
private String url;
|
||||
@CsvBindByName(column = "Latency")
|
||||
private String latency;
|
||||
@CsvBindByName(column = "IdleTime")
|
||||
private String idleTime;
|
||||
@CsvBindByName(column = "Connect")
|
||||
private String connect;
|
||||
|
||||
|
||||
public String getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void setTimestamp(String timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public String getElapsed() {
|
||||
return elapsed;
|
||||
}
|
||||
|
||||
public void setElapsed(String elapsed) {
|
||||
this.elapsed = elapsed;
|
||||
}
|
||||
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public String getResponseCode() {
|
||||
return responseCode;
|
||||
}
|
||||
|
||||
public void setResponseCode(String responseCode) {
|
||||
this.responseCode = responseCode;
|
||||
}
|
||||
|
||||
public String getResponseMessage() {
|
||||
return responseMessage;
|
||||
}
|
||||
|
||||
public void setResponseMessage(String responseMessage) {
|
||||
this.responseMessage = responseMessage;
|
||||
}
|
||||
|
||||
public String getThreadName() {
|
||||
return threadName;
|
||||
}
|
||||
|
||||
public void setThreadName(String threadName) {
|
||||
this.threadName = threadName;
|
||||
}
|
||||
|
||||
public String getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
public void setDataType(String dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(String success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getFailureMessage() {
|
||||
return failureMessage;
|
||||
}
|
||||
|
||||
public void setFailureMessage(String failureMessage) {
|
||||
this.failureMessage = failureMessage;
|
||||
}
|
||||
|
||||
public String getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public void setBytes(String bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public String getSentBytes() {
|
||||
return sentBytes;
|
||||
}
|
||||
|
||||
public void setSentBytes(String sentBytes) {
|
||||
this.sentBytes = sentBytes;
|
||||
}
|
||||
|
||||
public String getGrpThreads() {
|
||||
return grpThreads;
|
||||
}
|
||||
|
||||
public void setGrpThreads(String grpThreads) {
|
||||
this.grpThreads = grpThreads;
|
||||
}
|
||||
|
||||
public String getAllThreads() {
|
||||
return allThreads;
|
||||
}
|
||||
|
||||
public void setAllThreads(String allThreads) {
|
||||
this.allThreads = allThreads;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getLatency() {
|
||||
return latency;
|
||||
}
|
||||
|
||||
public void setLatency(String latency) {
|
||||
this.latency = latency;
|
||||
}
|
||||
|
||||
public String getIdleTime() {
|
||||
return idleTime;
|
||||
}
|
||||
|
||||
public void setIdleTime(String idleTime) {
|
||||
this.idleTime = idleTime;
|
||||
}
|
||||
|
||||
public String getConnect() {
|
||||
return connect;
|
||||
}
|
||||
|
||||
public void setConnect(String connect) {
|
||||
this.connect = connect;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue