|
| 1 | +--- |
| 2 | +title: 'Dynatrace' |
| 3 | +excerpt: Send k6 output to Dynatrace to visualize load test results and correlate performance testing metrics in Dynatrace. |
| 4 | +--- |
| 5 | + |
| 6 | +Using the [Dynatrace k6 extension](https://github.com/Dynatrace/xk6-output-dynatrace) you can send metrics to [Dynatrace](https://www.dynatrace.com/). That allows visualizing and correlating performance testing metrics with other monitored metrics in Dynatrace. |
| 7 | + |
| 8 | +## Build the k6 version |
| 9 | + |
| 10 | +<InstallationInstructions extensionUrl="github.com/Dynatrace/xk6-output-dynatrace"/> |
| 11 | + |
| 12 | +## Run the test |
| 13 | + |
| 14 | +Create a Dynatrace API token to send the data. |
| 15 | + |
| 16 | +<Blockquote mod="attention"> |
| 17 | +The Dynatrace API Token must have the scope name "metrics.ingest" (scope type "API v2"). |
| 18 | +</Blockquote> |
| 19 | + |
| 20 | +You can use the Dynatrace UI: |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +Or a `curl` command (replace `<environment-id>` and the `Api-Token`): |
| 25 | + |
| 26 | +```bash |
| 27 | +curl -X POST "https://<environment-id>.live.dynatrace.com/api/v2/apiTokens" -H "accept: application/json; charset=utf-8" -H "Content-Type: application/json; charset=utf-8" -d "{\"name\":\"\",\"scopes\":[\"metrics.ingest\"]}" -H "Authorization: Api-Token XXXXXXXX" |
| 28 | +``` |
| 29 | + |
| 30 | +Use the previously built k6 binary and run the test passing the Dynatrace URL and API token as follows: |
| 31 | + |
| 32 | +```bash |
| 33 | +# export dynatrace variables |
| 34 | +export K6_DYNATRACE_URL=https://<environmentid>.live.dynatrace.com |
| 35 | +export K6_DYNATRACE_APITOKEN=<Dynatrace API token> |
| 36 | + |
| 37 | +# run the test |
| 38 | +./k6 run script.js -o output-dynatrace |
| 39 | +``` |
| 40 | + |
| 41 | +You can now check the metrics in your Dynatrace environment, filtering for `k6`: |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +### Options |
| 48 | + |
| 49 | +When streaming the k6 results to Dynatrace, you can configure the Dynatrace options below: |
| 50 | + |
| 51 | +| Name | Value | |
| 52 | +| ---------------------------------------- | ----------------------------------------------------------------------------------------------------------- | |
| 53 | +| `K6_DYNATRACE_APITOKEN` | Dynatrace API token to write the metrics. The token must have the scope `metrics.ingest API v2`. | |
| 54 | +| `K6_DYNATRACE_FLUSH_PERIOD` | Define how often metrics are sent to Dynatrace. The default value is 1 second. | |
| 55 | +| `K6_DYNATRACE_URL` | Dynatrace URL. The default value is `https://dynatrace.live.com`. | |
| 56 | +| `K6_DYNATRACE_INSECURE_SKIP_TLS_VERIFY` | If `true`, the HTTP client kips TLS verification on the endpoint. The default value is `true`. | |
| 57 | +| `K6_DYNATRACE_HEADER` | Pair of key/value headers to add to Dynatrace requests. | |
0 commit comments