Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/anasoid/jmeter-logstash

Jmeter JTL parsing with Logstash for Elasticseacrh and Influxdb ...
https://github.com/anasoid/jmeter-logstash

elasticsearch elk filebeat grafana infuxdb jmeter jtl kibana logstash report reporting

Last synced: 2 months ago
JSON representation

Jmeter JTL parsing with Logstash for Elasticseacrh and Influxdb ...

Lists

README

        

# 1. jmeter-logstash

Jmeter JTL ans statiscts file parsing with Logstash and elasticsearch, you can find image
on [Docker Hub](https://hub.docker.com/r/anasoid/jmeter-logstash), statistics.json file is generated with jmeter html
report.

# 2. Quick reference

- **Where to get help**:
- [Issues](https://github.com/anasoid/jmeter-logstash/issues)
- [Discussions](https://github.com/anasoid/jmeter-logstash/discussions)
- [Documentation](https://github.com/anasoid/jmeter-logstash)

## 2.1. Image version

- [`latest`, `7.17`, `7.17.14`](https://github.com/anasoid/jmeter-logstash/blob/master/docker/elasticsearch/Dockerfile)
- [`8.4`, `8.4.2`](https://github.com/anasoid/jmeter-logstash/blob/master/docker/elasticsearch/Dockerfile)
- [`8.3`, `8.3.3`](https://github.com/anasoid/jmeter-logstash/blob/master/docker/elasticsearch/Dockerfile)
- [`8.2`, `8.2.3`](https://github.com/anasoid/jmeter-logstash/blob/master/docker/elasticsearch/Dockerfile)
- [`8.1`, `8.1.3`](https://github.com/anasoid/jmeter-logstash/blob/master/docker/elasticsearch/Dockerfile)

## 2.2. Features

1. Parse Standard JTL (CSV Format).
2. Possibility to filter requests based on regex filter (include and exclude filter) .
3. Flag samplers generated by TransactionController based on regex (by default '_.+_').
4. For TransactionController, calculate number of failing sampler and total.
5. Add relative time to compare different Executions, variable TESTSTART.MS should be logged with
property [sample_variables](https://jmeter.apache.org/usermanual/properties_reference.html#results_file_config)
6. Add Project name, test name, environment and executionId to organize results and compare different execution.
7. Split Label name to have multi tags by request (by default split by '/').
8. Flag subresult, when there is a redirection 302,.. Subrequest has a have a suffix like "-xx" when xx is the order
number
9. Supporting ElasticSearch and can be adapted for other tools.
10. can also index custom field logged in file with
property : [sample_variables](https://jmeter.apache.org/usermanual/properties_reference.html#results_file_config)

## 2.3. Content

- [1. jmeter-logstash](#1-jmeter-logstash)
- [2. Quick reference](#2-quick-reference)
- [2.1. Image version](#21-image-version)
- [2.2. Features](#22-features)
- [2.3. Content](#23-content)
- [2.4. Image Variants](#24-image-variants)
- [3. Getting Started](#3-getting-started)
- [3.1. Create ElasticSearch stack (_Only if using ElasticSearch \& Kibana_)](#31-create-elasticsearch-stack-only-if-using-elasticsearch--kibana)
- [3.2. Run Logstash](#32-run-logstash)
- [3.2.1. Run With image from docker hub for Elasticsearch (way 1, preferred)](#321-run-with-image-from-docker-hub-for-elasticsearch-way-1-preferred)
- [3.3. Dashboards](#33-dashboards)
- [3.3.1. Kibana](#331-kibana)
- [3.4. HOW-TO](#34-how-to)
- [3.4.1. Example](#341-example)
- [3.5. Parameters](#35-parameters)
- [3.5.1. ElasticSearch configuration](#351-elasticsearch-configuration)
- [3.5.2. Logstash](#352-logstash)
- [3.6. Fields](#36-fields)
- [3.6.1. Common](#361-common)
- [3.6.2. JTL](#362-jtl)
- [3.6.3. Statistics (Only ElasticSearch)](#363-statistics-only-elasticsearch)
- [4. Troubleshooting \& Limitation](#4-troubleshooting--limitation)

## 2.4. Image Variants

The `jmeter-logstash` images come in many flavors, each designed for a specific use case.
The images version are based on component used to build image, default use elasticsearch output:

1. **Logstash Version**: 7.17.9 -> default for 7.17.

# 3. Getting Started

## 3.1. Create ElasticSearch stack (_Only if using ElasticSearch & Kibana_)

1. Create Optional docker network (Called jmeter). If not used remove "--net jmeter " from all following docker command
and adapt Elasticsearch url.

```shell
docker network create jmeter
```

2. Start elastic search container , Or use any Elasticsearch instance you have already installed.

```shell
docker run --name jmeter-elastic --net jmeter \
-p 9200:9200 -p 9300:9300 \
-e "ES_JAVA_OPTS=-Xms1024m -Xmx1024m" \
-e "xpack.security.enabled=false" \
-e "discovery.type=single-node" \
docker.elastic.co/elasticsearch/elasticsearch:8.4.1
```

3. Start Kibana and connect it to elastic search Using environnement variable _ELASTICSEARCH_HOSTS_.

```shell
docker run --name jmeter-kibana --net jmeter -p 5601:5601 -e "ELASTICSEARCH_HOSTS=http://jmeter-elastic:9200" docker.elastic.co/kibana/kibana:8.4.1
```

## 3.2. Run Logstash

1. In the project folder create a folder named 'input' or you can use any input folder in your machine.
1. If you choose to use a different input folder, you should change **"${PWD}/input"** on the following command by your
input folder.

### 3.2.1. Run With image from docker hub for Elasticsearch (way 1, preferred)

```shell

#Run Image
docker run --rm -it --net jmeter -e "ELASTICSEARCH_HOSTS=http://jmeter-elastic:9200" -v ${PWD}/input:/input/ anasoid/jmeter-logstash

```

## 3.3. Dashboards

### 3.3.1. Kibana

Download Dashboards from [Kibana Dashboards](/docs/kibana/jmeter-jtl-kibana.ndjson) and go to Stack management kibana ->
saved object for import.

| Main Dashboard | Compare Dashboard |
|---------------------------------------------------------------|-----------------------------------------------------------------------|
| | |

## 3.4. HOW-TO

1. To exit after all files parsed use (**-e "FILE_EXIT_AFTER_READ=true"**) should be used with ( **-e "
FILE_READ_MODE=read"**) ..
2. To not remove container logstash after execution not use --rm from arguments.
3. Logstash keep information on position f last line parsed in a file sincedb, this file by default is on the path
_/usr/share/logstash/data/plugins/inputs/file_, if you use the same container this file will be persisted even you
restart logstash cotainer, and if you need to maintain this file even you remove container you can mount volume
folder in the path (_/usr/share/logstash/data/plugins/inputs/file_)
4. To have relative time for comparison test start time should be logged :
in user.properties file (sample_variables=TESTSTART.MS,...) or add properties with file using -q argument or directly
in command line with (-Jsample_variables=TESTSTART.MS,..)
see [Full list of command-line options](https://jmeter.apache.org/usermanual/get-started.html#options)

### 3.4.1. Example

Run Logstash without remove container after stop.

```shell
docker run -it --net jmeter -e "ELASTICSEARCH_HOSTS=http://jmeter-elastic:9200" \
-v ${PWD}/input:/input/ \
anasoid/jmeter-logstash

```

Run Logstash and remove file after the end of reading.

````shell
docker run --rm -it --net jmeter -e "ELASTICSEARCH_HOSTS=http://jmeter-elastic:9200" \
-v ${PWD}/input:/input/ \
-e "FILE_READ_MODE=read" \
-e "FILE_COMPLETED_ACTION=delete" \
anasoid/jmeter-logstash

Run Logstash with external sincedb folder.

```shell
docker run --rm -it --net jmeter -e "ELASTICSEARCH_HOSTS=http://jmeter-elastic:9200" \
-v ${PWD}/input:/input/ \
-v ${PWD}/.sincedb:/usr/share/logstash/data/plugins/inputs/file \
anasoid/jmeter-logstash

````

## 3.5. Parameters

### 3.5.1. ElasticSearch configuration

| Environment variables | Description | Default |
|----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------|
| `ELASTICSEARCH_HOSTS` | Elasticsearch output configuration [hosts](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-hosts) (ex: http://elasticsearch:9200 ) | |
| `ELASTICSEARCH_INDEX` | Elasticsearch output configuration [index](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-index) | jmeter-jtl-%{+YYYY.MM.dd} |
| `ELASTICSEARCH_USER` | Elasticsearch output configuration [user](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-user) | |
| `ELASTICSEARCH_PASSWORD` | Elasticsearch output configuration [password](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-password) | |
| `ELASTICSEARCH_SSL_VERIFICATION` | Elasticsearch output configuration [ssl_certificate_verification](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-ssl_certificate_verification) | true |
| `ELASTICSEARCH_HTTP_COMPRESSION` | Elasticsearch output configuration [http_compression](https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html#plugins-outputs-elasticsearch-http_compression) | false |
| `ELASTICSEARCH_VERSION` | Elasticsearch template version, shoud be the same as elasticsearch version (not logstash version), valid values are 7 and 8. Only logstash 7 who can work with Elasticsearch 7 and 8, logstash 8 work only with elasticsearch 8. | 7 for logstash 7.x et 8 for logstash 8.x |

### 3.5.2. Logstash

| Environment variables | Description | Default |
|--------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|
| `INPUT_PATH` | Default folder input used for JTL and statistics file. | /input |
| `INPUT_PATH_JTL` | Default folder input used for JTL, pattern : (`["${INPUT_PATH:/input}/**.jtl","${INPUT_PATH_JTL:/input}/**.jtl"]`) | /input |
| `INPUT_PATH_STAT` | Default folder input used statistics , pattern : (`["${INPUT_PATH:/input}/**.json","${INPUT_PATH_STAT:/input}/**.json"]`) | /input |
| `PROJECT_NAME` | Project name | undefined |
| `ENVIRONMENT_NAME` | Environment name, if not provided will try to extract value from file name ( {test_name}-{environment-name}-{execution_id} ) | undefined |
| `TEST_NAME` | Test name, if not provided will try to extract value from file name ( {test_name}-{environment-name}-{execution_id} or {test_name}-{execution_id} or {test_name}) | undefined |
| `TEST_METADATA` | Test metadata as key value ex : (version=v1,type=daily,region=europe). | |
| `TEST_TAGS` | Test tags, can add testtags fields as liste of value ex : (v1,daily,europe) version. | |
| `EXECUTION_ID` | Execution Id, if not provided will try to extract value from file name ( {test_name}-{environment-name}-{execution_id} or {test_name}-{execution_id} ) | undefined |
| `FILE_READ_MODE` | File input configuration [mode](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html#plugins-inputs-file-mode) | tail |
| `FILE_START_POSITION` | File input configuration [start_position](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html#plugins-inputs-file-start_position) | beginning |
| `FILE_EXIT_AFTER_READ` | File input configuration [exit_after_read](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html#plugins-inputs-file-exit_after_read) | false |
| `FILE_COMPLETED_ACTION` | File input configuration [file_completed_action](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html#plugins-inputs-file-file_completed_action) | log |
| `MISSED_RESPONSE_CODE` | Default response code when not present in response like on timeout case | 510 |
| `PARSE_LABELS_SPLIT_CHAR` | Char to split label into labels | / |
| `PARSE_TRANSACTION_REGEX` | Regex to identify transaction Label | \_.+\_ |
| `PARSE_TRANSACTION_AUTO` | Detect transaction controller based on URL null, and message format. | true |
| `PARSE_FILTER_INCLUDE_SAMPLER_REGEX` | Regex used to include samplers and transactions. | |
| `PARSE_FILTER_EXCLUDE_SAMPLER_REGEX` | Regex used to exclude samplers and transactions. | |
| `PARSE_REMOVE_TRANSACTION` | Remove transaction. | false |
| `PARSE_REMOVE_SAMPLER` | Remove sampler, not transaction. | false |
| `PARSE_REMOVE_MESSAGE_FIELD` | Remove field message. | true |
| `PARSE_CLEANUP_FIELDS` | Remove fields : host, path. | true |
| `PARSE_WITH_FLAG_SUBRESULT` | Flag result with prefix like have a suffix like "-xx" when xx is the order number | true |
| `PCT1` | percent 1 value for statistics report | 90 |
| `PCT2` | percent 1 value for statistics report | 95 |
| `PCT3` | percent 1 value for statistics report | 99 |

## 3.6. Fields

### 3.6.1. Common

Common field are integrated during file parsing for both JTL ans statistics file.

| Fields | Type ELK | source | Description |
|---------------|----------|---------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `origin` | string | - | Origin of message **jtl** or **stat** |
| `@timestamp` | date | elk | Insertion time in Elastic search |
| `environment` | string | input/parsing | Target environment (Ex: dev, stage ..), as input using environment variable or extracted from filename. |
| `executionid` | string | input/parsing | Unique id to identify data for a test, as input using environment variable or extracted from filename. |
| `filename` | string | parsing | file name without extension. |
| `path` | string | logstash | Path of file. |
| `project` | string | input | Project name. |
| `testname` | string | parsing | Test name, as input using environment variable or extracted from filename. |
| `testtags` | string | parsing | List of keywords extracted by splitting environnement variable "TEST_TAGS" from environment variable |
| `timestamp` | date | csv | Request time. Accept timestamp format in ms or "yyyy/MM/dd HH:mm:ss.SSS" . |
| `label` | string | csv | sampler label |
| `labels` | string | parsing | List of keywords extracted by splitting label using the char "PARSE_LABELS_SPLIT_CHAR" from environment variable , default to "/" |
| `globalLabel` | string | parsing | Normalized label for subresults, when there redirection (ex 302) jmeter log all redirects requests and the parent one by default (_jmeter.save.saveservice.subresults=false_ to disable), the parent will have the normal label and other subresut will have a suffix like "-xx" when xx is the order number, in this field you will find the original label for all subresult without the number suffix (see field : subresult, redirectLevel ) |

### 3.6.2. JTL

Fields for JTL File.
For csv field see documentation on [CSV Log format](https://jmeter.apache.org/usermanual/listeners.html#csvlogformat).

For additional fields see documentation
on [Results file configuration](https://jmeter.apache.org/usermanual/properties_reference.html#results_file_config).

| Fields | Type ELK | source | Description |
|-----------------------------|----------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `Connect` | long | csv | time to establish connection |
| `IdleTime` | long | csv | number of milliseconds of 'Idle' time (normally 0) |
| `Latency` | long | csv | time to first response |
| `URL` | string | csv | |
| `allThreads` | long | csv | total number of active threads in all groups |
| `bytes` | long | csv | number of bytes in the sample |
| `dataType` | string | csv | e.g. text |
| `domain` | string | parsing | domain name or ip which is extracted from url. |
| `elapsed` | long | csv | elapsed - in milliseconds |
| `failureMessage` | string | csv | |
| `grpThreads` | long | csv | number of active threads in this thread group |
| `host` | string | elk | hostname of logstash node. |
| `redirectLevel` | long | parsing | redirect number (see field: _globalLabel_) |
| `relativetime` | float | parsing | Number of milliseconds from test started. Useful to compare test. this field need to have started test time logged to csv (add this variable name _TESTSTART.MS_ to property _sample_variables_) |
| `request` | string | parsing | Request path if Http/s request. |
| `responseCode` | string | csv | |
| `responseMessage` | string | csv | |
| `responseStatus` | long | parsing | Numeric responseCode , if responseCode is not numeric (case on timeout) using value "MISSED_RESPONSE_CODE" from environment variable , default to 510. |
| `sentBytes` | long | csv | number of bytes sent for the sample. |
| `subresult` | boolean | parsing | true if sample is a sub result (see field: _globalLabel_) |
| `success` | boolean | csv | true or false. |
| `teststart` | date | csv | Test start time. This field need to have started test time logged to csv (add this variable name _TESTSTART.MS_ to property _sample_variables_) |
| `threadGrpId` | long | parsing | The number of thread group. (Extract from threadName) . |
| `threadGrpName` | string | parsing | The name of thread group.(Extract from threadName) . |
| `workerNode` | string | parsing | host port of worker node. (Extract from threadName) . |
| `threadNumber` | long | parsing | The number of thread (unique in thread group). (Extract from threadName) . |
| `threadName` | string | csv | Thread name, unique on test. |
| `transaction` | boolean | parsing | IS Sampler transaction , generated by transaction controller, to identify transaction label should start and and with "\_", the regex used to this is "\_.+\_" |
| `transactionFailingSampler` | long | parsing | If sample is transaction, this value represent number of failing sampler. |
| `transactionTotalSampler` | long | parsing | If sample is transaction, this value represent count of total sampler. |

### 3.6.3. Statistics (Only ElasticSearch)

Fields for Statistics

For percentiles configuration (pc1,pc2,pc3)
see [Percentiles configuration](https://jmeter.apache.org/usermanual/properties_reference.html#aggregate_report_graph).

| Fields | Type ELK | source | Description |
|------------------------|----------|---------|----------------------------------------------------------------------------------------|
| `isTotal` | boolean | Parsing | Is total line, label will be "Total" |
| `sampleCount` | long | Parsing | Sample count |
| `errorPct` | long | Parsing | Percent of error |
| `errorCount` | long | Parsing | Error count |
| `receivedKBytesPerSec` | long | Parsing | Received Kilo Bytes per seconds |
| `sentKBytesPerSec` | long | Parsing | Sent Kilo Bytes per seconds |
| `throughput` | long | Parsing | Throughput |
| `pct1ResTime` | long | Parsing | Percentile 1 response time (aggregate_rpt_pct1) |
| `pct90` | long | Parsing | percentile 1 value, field name can be changed with PCT1 see [configuration](#logstash) |
| `pct2ResTime` | long | Parsing | Percentile 2 response time (aggregate_rpt_pct2) |
| `pct95` | long | Parsing | percentile 2 value, field name can be changed with PCT1 see [configuration](#logstash) |
| `pct3ResTime` | long | Parsing | Percentile 3 response time (aggregate_rpt_pct3) |
| `pct99` | long | Parsing | percentile 3 value, field name can be changed with PCT1 see [configuration](#logstash) |
| `minResTime` | long | Parsing | Minimum response time. |
| `meanResTime` | long | Parsing | Mean response time. |
| `medianResTime` | long | Parsing | Median response time. |
| `maxResTime` | long | Parsing | MAximum response time. |

# 4. Troubleshooting & Limitation

1. Logstash instance can't parse CSV file with different header Format, as first header will be used for all file, if
you have files with different format you should use each time a new instance or restart the instance.
1. Change sincedb file can't done on logstash with Elasticsearch without building image.
1. Label with suffix '-{number}' will be considered as subresult, so don't prefix label with '-{number}' or disable
subresult flag with PARSE_WITH_FLAG_SUBRESULT.