Skip to content

Commit bf6135c

Browse files
Added injector hostname as a value in the base index
1 parent cc87f48 commit bf6135c

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>io.github.delirius325</groupId>
55
<artifactId>jmeter.backendlistener.elasticsearch</artifactId>
6-
<version>2.3.2</version>
6+
<version>2.3.3</version>
77
<packaging>jar</packaging>
88

99
<name>jmeter.backendlistener.elasticsearch</name>

src/main/java/io/github/delirius325/jmeter/backendlistener/elasticsearch/ElasticsearchBackend.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.delirius325.jmeter.backendlistener.elasticsearch;
22

33
import java.io.IOException;
4+
import java.net.InetAddress;
45
import java.text.ParseException;
56
import java.text.SimpleDateFormat;
67
import java.time.LocalDateTime;
@@ -47,6 +48,7 @@ public class ElasticsearchBackend extends AbstractBackendListenerClient {
4748
private List<String> filters;
4849
private RestClient client;
4950
private String index;
51+
private String injectorHostname;
5052
private int buildNumber;
5153
private int bulkSize;
5254
private long timeoutMs;
@@ -72,13 +74,14 @@ public void setupTest(BackendListenerContext context) throws Exception {
7274
try {
7375
String host = context.getParameter(ES_HOST);
7476
int port = Integer.parseInt(context.getParameter(ES_PORT));
75-
76-
this.filters = new LinkedList<String>();
77-
this.bulkRequestList = new LinkedList<String>();
78-
this.index = context.getParameter(ES_INDEX).toLowerCase();
79-
this.bulkSize = Integer.parseInt(context.getParameter(ES_BULK_SIZE));
80-
this.timeoutMs = JMeterUtils.getPropDefault(ES_TIMEOUT_MS, DEFAULT_TIMEOUT_MS);
81-
this.buildNumber = (JMeterUtils.getProperty(ElasticsearchBackend.BUILD_NUMBER) != null && JMeterUtils.getProperty(ElasticsearchBackend.BUILD_NUMBER).trim() != "") ? Integer.parseInt(JMeterUtils.getProperty(ElasticsearchBackend.BUILD_NUMBER)) : 0;
77+
78+
this.injectorHostname = InetAddress.getLocalHost().getHostName();
79+
this.filters = new LinkedList<String>();
80+
this.bulkRequestList = new LinkedList<String>();
81+
this.index = context.getParameter(ES_INDEX).toLowerCase();
82+
this.bulkSize = Integer.parseInt(context.getParameter(ES_BULK_SIZE));
83+
this.timeoutMs = JMeterUtils.getPropDefault(ES_TIMEOUT_MS, DEFAULT_TIMEOUT_MS);
84+
this.buildNumber = (JMeterUtils.getProperty(ElasticsearchBackend.BUILD_NUMBER) != null && JMeterUtils.getProperty(ElasticsearchBackend.BUILD_NUMBER).trim() != "") ? Integer.parseInt(JMeterUtils.getProperty(ElasticsearchBackend.BUILD_NUMBER)) : 0;
8285
this.client = RestClient.builder(new HttpHost(context.getParameter(ES_HOST), port, context.getParameter(ES_SCHEME)))
8386
.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000)
8487
.setSocketTimeout((int) timeoutMs))
@@ -203,7 +206,7 @@ public Map<String, Object> getElasticData(SampleResult sr, BackendListenerContex
203206
jsonObject.put("Timestamp", sdf.format(new Date(sr.getTimeStamp())));
204207
jsonObject.put("StartTimeInMs", sr.getStartTime());
205208
jsonObject.put("EndTimeInMs", sdf.format(new Date(sr.getEndTime())));
206-
// jsonObject.put("ElapsedTimeInMs", sdf.format(new Date(System.currentTimeMillis() - sr.getStartTime())));
209+
jsonObject.put("InjectorHostname", this.injectorHostname);
207210
jsonObject.put("ResponseCode", (sr.getResponseCode()));
208211
jsonObject.put(ElasticsearchBackend.BUILD_NUMBER, this.buildNumber);
209212

0 commit comments

Comments
 (0)