Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 55fe9ae

Browse files
authored
Merge pull request #98 from jwcastillo/dashboard_apdex
Grafana dashboards improvements
2 parents 7d4b8d8 + 0d0430f commit 55fe9ae

20 files changed

+3254
-1363
lines changed

README.md

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# xk6-output-prometheus-remote
2+
23
[k6](https://github.com/grafana/k6) extension for publishing test-run metrics to Prometheus via Remote Write endpoint.
34

45
> :warning: Not to be confused with [Prometheus Remote Write **client** extension](https://github.com/grafana/xk6-client-prometheus-remote) which is for load testing _Prometheus_ itself.
56
6-
> :bookmark: As of k6 v0.42.0, this extension is available within k6 as an _experimental module_.
7+
> :bookmark: As of k6 v0.42.0, this extension is available within k6 as an _experimental module_.
78
> This means that the extension has entered the process of being fully merged into the core of k6 and does not require a special build with xk6 to utilize this feature.
8-
>
9+
>
910
> See the [Prometheus remote write guide](https://k6.io/docs/results-output/real-time/prometheus-remote-write/) to utilize this feature.
10-
>
11+
>
1112
1213
There are many options for remote-write compatible agents, the official list can be found [here](https://prometheus.io/docs/operating/integrations/). The exact details of how metrics will be processed or stored depends on the underlying agent used.
1314

@@ -20,16 +21,19 @@ Key points to know:
2021
### Usage
2122

2223
To build k6 binary with the Prometheus remote write output extension use:
24+
2325
```
2426
xk6 build --with github.com/grafana/xk6-output-prometheus-remote@latest
2527
```
2628

2729
Then run new k6 binary with:
30+
2831
```
2932
K6_PROMETHEUS_RW_SERVER_URL=http://localhost:9090/api/v1/write ./k6 run -o xk6-prometheus-rw script.js
3033
```
3134

3235
Add TLS and HTTP basic authentication:
36+
3337
```
3438
K6_PROMETHEUS_RW_SERVER_URL=https://localhost:9090/api/v1/write \
3539
K6_PROMETHEUS_RW_INSECURE_SKIP_TLS_VERIFY=false \
@@ -51,17 +55,17 @@ All the k6 metric types are converted into an equivalent Prometheus' type:
5155

5256
The obvious conversion with a classic Prometheus Histogram is not convenient because k6 can't determine the fixed buckets in advance, so the Output maps a Trend metric by default into a Gauge representing p(99). It is possible to map the same Trend to multiple stats at the same time (count, sum, min, max, avg, med, p(x)), it is possible to specify them via the `K6_PROMETHEUS_RW_TREND_STATS` environment variable (e.g `K6_PROMETHEUS_RW_TREND_STATS=avg,p(90),p(99),min,max`). Note that for each added stat a new time series will be generated.
5357
Mapping Trend by stats has the following cons:
54-
* It is impossible to aggregate some Gauge's value (especially the percentiles).
55-
* It uses a memory-expensive k6's data structure.
58+
59+
- It is impossible to aggregate some Gauge's value (especially the percentiles).
60+
- It uses a memory-expensive k6's data structure.
5661

5762
The previous points can be resolved by mapping Trend as [Prometheus Native Histogram](https://prometheus.io/docs/concepts/metric_types/#histogram). Enabling the conversion by the `K6_PROMETHEUS_RW_TREND_AS_NATIVE_HISTOGRAM=true` environment variable (or one of the other ways), then the Output converts all the Trend types into a dedicated Native Histogram.
5863

5964
Native Histogram is a Prometheus' experimental feature, so it has to be enabled (`--enable-feature=native-histograms`). Note that other Remote-write implementations don't support it yet.
6065

6166
### Prometheus as remote-write agent
6267

63-
To enable remote write in Prometheus 2.x use `--enable-feature=remote-write-receiver` option. See docker-compose samples in `example/`. Options for remote write storage can be found [here](https://prometheus.io/docs/operating/integrations/).
64-
68+
To enable remote write in Prometheus 2.x use `--enable-feature=remote-write-receiver` option. See docker-compose samples in `example/`. Options for remote write storage can be found [here](https://prometheus.io/docs/operating/integrations/).
6569

6670
### Docker Compose
6771

@@ -71,13 +75,14 @@ Note: the `docker-compose.yml` file has the Native Histogram mapping set as enab
7175

7276
> This is just a quick setup to show the usage. For a real use case, you will want to deploy outside of docker.
7377
74-
Clone the repo to get started and follow these steps:
78+
Clone the repo to get started and follow these steps:
7579

7680
1. Start the docker compose environment.
81+
7782
```shell
7883
docker-compose up -d
7984
```
80-
85+
8186
> Some users have encountered failures for the k6 build portion. A workaround may be to disable the _"Use Docker Compose V2"_ checkbox in the _General_ section of Docker Desktop settings.
8287

8388
```shell
@@ -88,23 +93,38 @@ Clone the repo to get started and follow these steps:
8893
```
8994

9095
2. Use the k6 Docker image to run the k6 script and send metrics to the Prometheus container started on the previous step. You must [set the `testid` tag](https://k6.io/docs/using-k6/tags-and-groups/#test-wide-tags) with a unique identifier to segment the metrics into discrete test runs for the Grafana dashboards.
96+
9197
```shell
9298
docker-compose run --rm -T k6 run -<samples/test.js --tag testid=<SOME-ID>
9399
```
100+
94101
For convenience, the `docker-run.sh` can be used to simply:
102+
95103
```shell
96104
./docker-run.sh samples/test.js
97105
```
98106

99-
3. Visit http://localhost:3000/ to view results in Grafana.
107+
3. Visit <http://localhost:3000/> to view results in Grafana.
100108

101109
## Dashboards
110+
102111
The docker-compose setup comes with two pre-built Grafana dashboards. One for listing the discrete test runs as a list, and the other for visualizing the results of a specific test run.
103112
>Note: The dashboards work with the Native Histogram mapping so it is required to enable it.
104113

105114
### Test result dashboard
106-
![Prometheus dashboard of k6 test result](./images/prometheus-dashboard-k6-test-result.png)
107115

108-
### Test list dashboard
109-
![Prometheus dashboard of k6 test runs](./images/prometheus-dashboard-k6-test-runs.png)
116+
[<img src="./images/prometheus-dashboard-k6-test-result.png" width="500"/>](./images/prometheus-dashboard-k6-test-result.png)
117+
118+
Results can be filtered by:
119+
120+
- testid
121+
- scenario
122+
- url
123+
124+
[<img src="./images/prometheus-dashboard-k6-test-result-variables.png" width="500"/>](./images/prometheus-dashboard-k6-test-result-variables.png)
125+
126+
Response time metrics are based on the **metrics** variable, and the values can be:
127+
128+
- k6_http_req_duration_seconds (default)
129+
- k6_http_req_waiting_seconds
110130

docker-run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ SCRIPT_NAME=$1
1919
TAG_NAME="$(basename -s .js $SCRIPT_NAME)-$(date +%s)"
2020

2121
docker-compose run --rm -T k6 run -<$SCRIPT_NAME --tag testid=$TAG_NAME
22+
# for testing without tags
23+
# docker-compose run --rm -T k6 run -<$SCRIPT_NAME

grafana/dashboards/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,77 @@
11
# Dashboards
22

33
Add custom dashboards here, then start the [docker-compose](../../docker-compose.yml) to have the dashboards provisioned at startup. Use folders to group related dashboards.
4+
5+
6+
7+
## Dashboards
8+
9+
The docker-compose setup comes with two pre-built Grafana dashboards. One for listing the discrete test runs as a list, and the other for visualizing the results of a specific test run.
10+
>Note: The dashboards work with the Native Histogram mapping so it is required to enable it.
11+
12+
### Test result dashboard
13+
14+
[<img src="./images/prometheus-dashboard-k6-test-result.png" width="500"/>](./images/prometheus-dashboard-k6-test-result.png)
15+
16+
Results can be filtered by:
17+
18+
- testid
19+
- scenario
20+
- url
21+
22+
[<img src="./images/prometheus-dashboard-k6-test-result-variables.png" width="500"/>](./images/prometheus-dashboard-k6-test-result-variables.png)
23+
24+
Response time metrics are based on the **metrics** variable, and the values can be:
25+
26+
- k6_http_req_duration_seconds (default)
27+
- k6_http_req_waiting_seconds
28+
29+
The board is structured into 4 sections
30+
31+
#### Performance Overview
32+
33+
[<img src="./images/prometheus-dashboard-k6-test-result-performance.png" width="500"/>](./images/prometheus-dashboard-k6-test-result-performance.png)
34+
35+
#### HTTP
36+
37+
[<img src="./images/prometheus-dashboard-k6-test-result-http.png" width="500"/>](./images/prometheus-dashboard-k6-test-result-http.png)
38+
39+
#### Scenarios
40+
41+
[<img src="./images/prometheus-dashboard-k6-test-result-scenarios.png" width="500"/>](./images/prometheus-dashboard-k6-test-result-scenarios.png)
42+
43+
### Test list dashboard
44+
45+
[<img src="./images/prometheus-dashboard-k6-test-runs.png" width="500"/>](./images/prometheus-dashboard-k6-test-runs.png)
46+
47+
>Note: This dashboard depends on the use of testid tag
48+
49+
50+
#### Apex Overview Dashboard
51+
52+
[<img src="./images/prometheus-dashboard-k6-test-result-apdex.png" width="500"/>](./images/prometheus-dashboard-k6-test-result-apdex.png)
53+
54+
The Apdex score is calculated based on your SLA ```([T]target time (seconds) Apdex
55+
variable, default 0.3 sec)``` required where you can define a response time threshold of T seconds, where all responses handled in T seconds or less satisfy the end user.
56+
57+
If you want to know more
58+
59+
<https://medium.com/@tristan_96324/prometheus-apdex-alerting-d17a065e39d0>
60+
61+
<https://en.wikipedia.org/wiki/Apdex>
62+
63+
<!--
64+
65+
#### Custom Metrics Example Dashboard
66+
67+
[<img src="./images/prometheus-dashboard-k6-test-result-apdex.png" width="500"/>](./images/prometheus-dashboard-k6-test-result-apdex.png)
68+
69+
This dashboard is an example of a dashboard with panels showing custom metrics.
70+
71+
To test this dashboard, you must run the test.
72+
73+
If you want to know more
74+
75+
<https://medium.com/@tristan_96324/prometheus-apdex-alerting-d17a065e39d0>
76+
77+
<https://en.wikipedia.org/wiki/Apdex> -->

0 commit comments

Comments
 (0)