Skip to content

Commit c491f28

Browse files
author
DABURON Vincent
committed
Version 1.4, Remove log4j 1.x library, upgrade libraries dependencies and maven plugins versions.
1 parent f69c3b4 commit c491f28

File tree

4 files changed

+77
-52
lines changed

4 files changed

+77
-52
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JMeter2Influxdb
22

3-
Read JMeter results in a csv file and put results in Influxdb database
3+
Read JMeter results in a csv file and put results in Influxdb V1.x database
44

55
The Influxdb database must be **CREATED** before import results.
66

@@ -138,3 +138,8 @@ Results and monitoring PerfMon, JMXMon, DBMon
138138

139139
# License
140140
See the LICENSE file (Apache 2) https://www.apache.org/licenses/LICENSE-2.0
141+
142+
# Versions
143+
Version 1.4 2025-04-09, Remove log4j 1.x library, upgrade libraries dependencies and maven plugins versions.
144+
145+
Version 1.3 2019-10-29, First publication to GitHub.

pom.xml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,31 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>io.github.soprasteria.jmeterplugins.influxdb</groupId>
55
<artifactId>jmeter2influxdb</artifactId>
6-
<version>1.3</version>
6+
<version>1.4</version>
77

88
<dependencies>
99
<dependency>
1010
<groupId>org.influxdb</groupId>
1111
<artifactId>influxdb-java</artifactId>
12-
<version>2.14</version>
12+
<version>2.25</version>
1313
</dependency>
1414
<dependency>
1515
<groupId>org.apache.commons</groupId>
1616
<artifactId>commons-csv</artifactId>
17-
<version>1.6</version>
17+
<version>1.14.0</version>
1818
</dependency>
1919
<dependency>
2020
<groupId>commons-cli</groupId>
2121
<artifactId>commons-cli</artifactId>
22-
<version>1.4</version>
23-
</dependency>
24-
<dependency>
25-
<groupId>log4j</groupId>
26-
<artifactId>log4j</artifactId>
27-
<version>1.2.17</version>
22+
<version>1.9.0</version>
2823
</dependency>
2924
</dependencies>
3025
<build>
3126
<plugins>
3227
<plugin>
3328
<groupId>org.apache.maven.plugins</groupId>
3429
<artifactId>maven-compiler-plugin</artifactId>
35-
<version>3.8.0</version>
30+
<version>3.14.0</version>
3631
<configuration>
3732
<source>1.8</source>
3833
<target>1.8</target>
@@ -41,7 +36,7 @@
4136
</plugin>
4237
<plugin>
4338
<artifactId>maven-assembly-plugin</artifactId>
44-
<version>3.1.1</version>
39+
<version>3.7.1</version>
4540
<configuration>
4641
<descriptorRefs>
4742
<descriptorRef>jar-with-dependencies</descriptorRef>

src/main/java/io/github/soprasteria/jmeterplugins/influxdb/ImportJMeterLogIntoInfluxdb.java

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.Map;
2929
import java.util.Properties;
3030
import java.util.concurrent.TimeUnit;
31+
import java.util.logging.Level;
32+
import java.util.logging.Logger;
3133

3234
import org.apache.commons.cli.CommandLine;
3335
import org.apache.commons.cli.CommandLineParser;
@@ -39,10 +41,7 @@
3941
import org.apache.commons.cli.ParseException;
4042
import org.apache.commons.csv.CSVFormat;
4143
import org.apache.commons.csv.CSVRecord;
42-
import org.apache.log4j.BasicConfigurator;
43-
import org.apache.log4j.Level;
44-
import org.apache.log4j.LogManager;
45-
import org.apache.log4j.Logger;
44+
4645
import org.influxdb.InfluxDB;
4746
import org.influxdb.InfluxDB.ConsistencyLevel;
4847
import org.influxdb.InfluxDBFactory;
@@ -52,7 +51,7 @@
5251

5352
/**
5453
*
55-
* <h1>JMeter results file to Influxdb</h1>
54+
* <h1>JMeter results file to Influxdb 1.x</h1>
5655
* <p>
5756
* Read a result JMeter file in csv format and
5857
* import all results in Influxdb Database
@@ -103,14 +102,13 @@ public class ImportJMeterLogIntoInfluxdb {
103102

104103
public static final int K_WRITE_MODULO = 1000; // write informations to InfluxDB every K_WRITE_MODULO lines
105104

106-
private static final Logger LOGGER = LogManager.getLogger(ImportJMeterLogIntoInfluxdb.class);
105+
private static final Logger LOGGER = Logger.getLogger( ImportJMeterLogIntoInfluxdb.class.getPackage().getName());
107106

108107
public static void main(String[] args) {
109-
110108
System.out.println("Begin main");
111109

112-
BasicConfigurator.configure();
113-
Logger.getRootLogger().setLevel(Level.WARN);
110+
long startMain = System.currentTimeMillis();
111+
LOGGER.setLevel(Level.WARNING);
114112

115113
Options options = createOptions();
116114
Properties parseProperties = null;
@@ -138,8 +136,23 @@ public static void main(String[] args) {
138136
boolean bMultiplyValueBy = false;
139137
double dMutiplyCoef = 0.001;
140138

139+
141140
String sTmp = "";
141+
sTmp = (String) parseProperties.get(K_LEVEL_TRACE_OPT);
142+
if (sTmp != null) {
143+
String traceLevel = sTmp;
144+
if (traceLevel.equalsIgnoreCase("WARN")) {
145+
LOGGER.setLevel(Level.WARNING);
146+
}
147+
148+
if (traceLevel.equalsIgnoreCase("INFO")) {
149+
LOGGER.setLevel(Level.INFO);
150+
}
142151

152+
if (traceLevel.equalsIgnoreCase("DEBUG")) {
153+
LOGGER.setLevel(Level.FINE);
154+
}
155+
}
143156
sTmp = (String) parseProperties.get(K_JMETER_FILE_IN_OPT);
144157
if (sTmp != null) {
145158
jmeterFileIn = sTmp;
@@ -200,37 +213,34 @@ public static void main(String[] args) {
200213
bMultiplyValueBy = true;
201214
}
202215

203-
204-
205-
sTmp = (String) parseProperties.get(K_LEVEL_TRACE_OPT);
206-
if (sTmp != null) {
207-
String traceLevel = sTmp;
208-
if (traceLevel.equalsIgnoreCase("WARN")) {
209-
Logger.getRootLogger().setLevel(Level.WARN);
210-
}
211-
212-
if (traceLevel.equalsIgnoreCase("INFO")) {
213-
Logger.getRootLogger().setLevel(Level.INFO);
214-
}
215-
216-
if (traceLevel.equalsIgnoreCase("DEBUG")) {
217-
Logger.getRootLogger().setLevel(Level.DEBUG);
218-
}
219-
}
220-
216+
int nbLines = 0;
221217
try {
222218
ImportJMeterLogIntoInfluxdb importJMeterLogIntoInfluxdb = new ImportJMeterLogIntoInfluxdb();
223-
importJMeterLogIntoInfluxdb.readJMeterFileAndWriteInInfluxDB(jmeterFileIn, jmeter_save_saveservice_timestamp_format, delimiter,
219+
nbLines = importJMeterLogIntoInfluxdb.readJMeterFileAndWriteInInfluxDB(jmeterFileIn, jmeter_save_saveservice_timestamp_format, delimiter,
224220
influxdbUrl, influxdbUser, influxdbPassword, dbName, testLabel, application, bParseResponseMessage, bMultiplyValueBy, dMutiplyCoef);
225221
} catch (Exception ex) {
226-
LOGGER.error(ex);
222+
LOGGER.severe(ex.toString());
223+
System.out.println("End main Error (exit 1)");
224+
System.exit(1);
225+
}
226+
if (nbLines == 0) {
227+
System.out.println("End main Error (exit 1)");
227228
System.exit(1);
228229
}
229-
System.out.println("End main (exit 0)");
230+
231+
// compute duration
232+
long endMain = System.currentTimeMillis();
233+
long durationMs = endMain - startMain;
234+
double averageLineMs = 0;
235+
if (nbLines > 0) {
236+
averageLineMs = ((double) durationMs / nbLines);
237+
}
238+
LOGGER.warning("Duration = " + durationMs + " ms (" + Utils.timeFormatDuration(durationMs) + ") for number of lines = " + nbLines + ", average ms by line = " + String.format( "%.3f",averageLineMs));
239+
System.out.println("End main OK (exit 0)");
230240
System.exit(0);
231241
}
232242

233-
public void readJMeterFileAndWriteInInfluxDB(String jmeterFileIn, String timeFormat, char delimiter,
243+
public int readJMeterFileAndWriteInInfluxDB(String jmeterFileIn, String timeFormat, char delimiter,
234244
String influxdbUrl, String influxdbUser, String influxdbPassword, String dbName, String testLabel,
235245
String application, boolean bParseResponseMessage, boolean bMultiplyValueBy, double dMutiplyCoef) throws Exception {
236246
InfluxDB influxDB = InfluxDBFactory.connect(influxdbUrl, influxdbUser, influxdbPassword);
@@ -253,14 +263,12 @@ public void readJMeterFileAndWriteInInfluxDB(String jmeterFileIn, String timeFor
253263
DecimalFormat decimalFormat = new DecimalFormat(pattern, symbols);
254264
decimalFormat.setParseBigDecimal(true);
255265

256-
266+
int lineNumber = 1;
257267
try {
258268
in = new FileReader(jmeterFileIn);
259269
Iterable<CSVRecord> records = CSVFormat.RFC4180.withFirstRecordAsHeader().withDelimiter(delimiter)
260270
.parse(in);
261271

262-
int lineNumber = 1;
263-
264272
for (CSVRecord record : records) {
265273

266274
JMeterSimpleSampler jsSampler = new JMeterSimpleSampler();
@@ -339,7 +347,7 @@ public void readJMeterFileAndWriteInInfluxDB(String jmeterFileIn, String timeFor
339347
}
340348
catch (Exception ex) {
341349
jsSampler.setResponseCode(responseCodeTmp);
342-
LOGGER.error("Put Response Code Error 500 because i can't parse Integer for ResponseCode :<" + sTmp + ">");
350+
LOGGER.severe("Put Response Code Error 500 because i can't parse Integer for ResponseCode :<" + sTmp + ">");
343351
}
344352
}
345353
}
@@ -367,7 +375,7 @@ public void readJMeterFileAndWriteInInfluxDB(String jmeterFileIn, String timeFor
367375
catch (Exception ex) {
368376
withResponseMessageLong = false;
369377
jsSampler.setResponseMessageLong(responseMessageLong);
370-
LOGGER.error("Put Response Message Long format, i can't parse Long for ResponseMessage :<" + sTmp + ">");
378+
LOGGER.severe("Put Response Message Long format, i can't parse Long for ResponseMessage :<" + sTmp + ">");
371379
}
372380
}
373381
}
@@ -396,7 +404,7 @@ public void readJMeterFileAndWriteInInfluxDB(String jmeterFileIn, String timeFor
396404
}
397405
catch (Exception ex) {
398406
jsSampler.setSuccess(successTmp);
399-
LOGGER.error("Put success to false because i can't parse Boolean for success :<" + sTmp + ">");
407+
LOGGER.severe("Put success to false because i can't parse Boolean for success :<" + sTmp + ">");
400408
}
401409
}
402410

@@ -532,7 +540,7 @@ public void readJMeterFileAndWriteInInfluxDB(String jmeterFileIn, String timeFor
532540
batchPoints.point(point);
533541

534542
if ((lineNumber % K_WRITE_MODULO) == 0) {
535-
LOGGER.warn("write batchPoints, lineNumber = " + lineNumber);
543+
LOGGER.warning("write batchPoints, lineNumber = " + lineNumber);
536544

537545
influxDB.write(batchPoints);
538546

@@ -552,11 +560,11 @@ public void readJMeterFileAndWriteInInfluxDB(String jmeterFileIn, String timeFor
552560
batchPoints.point(pointEvt);
553561
}
554562

555-
LOGGER.warn("End write batchPoints, lineNumber = " + lineNumber);
563+
LOGGER.warning("End write batchPoints, lineNumber = " + lineNumber);
556564
influxDB.write(batchPoints);
557565

558566
} catch (Exception ex) {
559-
LOGGER.error(ex);
567+
LOGGER.severe(ex.toString());
560568
throw ex;
561569
} finally {
562570
if (in != null) {
@@ -575,6 +583,7 @@ public void readJMeterFileAndWriteInInfluxDB(String jmeterFileIn, String timeFor
575583
}
576584
}
577585
}
586+
return lineNumber;
578587
}
579588

580589
private static Options createOptions() {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.soprasteria.jmeterplugins.influxdb;
2+
3+
public class Utils {
4+
5+
public static String timeFormatDuration(long millisec) {
6+
long seconds = (millisec / 1000);
7+
long sec = seconds % 60;
8+
long min = (seconds / 60) % 60;
9+
long hrs = (seconds / (60 * 60)) % 24;
10+
if (hrs > 0) {
11+
return String.format("%02d hour, %02d min, %02d sec", hrs, min, sec);
12+
} else {
13+
return String.format("%02d min, %02d sec", min, sec);
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)