k6 can send telemetry data to New Relic through the New Relic StatsD integration. Within New Relic you can find your k6 performance data alongside your real users data and server side performance. This data can be visualized in dashboards and shared with others, used to compare load impact with system performance, and alert on metrics too.
This guide covers running the New Relic integration:
- Run the New Relic StatsD integration
- Run the k6 test
- Visualize k6 telemetry in New Relic
To get k6 metrics into New Relic, k6 sends metrics to the New Relic StatsD integration which will take care of collecting, aggregate, format and send the telemetry to the New Relic Telemetry Data Platform. You can run this with or without a New Relic agent.
Run the New Relic integration as a Docker container with this command:
docker run \ -d --restart unless-stopped \ --name newrelic-statsd \ -h $(hostname) \ -e NR_ACCOUNT_ID=<NR-ACCOUNT-ID> \ -e NR_API_KEY="<NR-INSERT-API-KEY>" \ -p 8125:8125/udp \ newrelic/nri-statsd:latest
If your account is hosted in the New Relic EU region, then also add this to the above command:
-e NR_EU_REGION=true \
The New Relic StatsD integration installed above can run standalone. Installing a New Relic agent is optional.
Everything provided in the command above is enough to send k6 performance metrics to New Relic. You can optionally however add further configuration, further define metrics and their formats (you can however do this on the New Relic side configuration), add custom tags, and create alerts. This is covered in the optional table below.
Once the integration is running, run the k6 test and send the metrics to the integration with:
$ k6 run --out statsd script.js
The required environment variables used in the above command are:
|The Account ID used in New Relic You can find your account ID here.|
|The Insert API Key for your New Relic account to send k6 telemetry to the account ID specified above. You can generate an Insert API key here.|
There are also optional environment variables you can use:
|Setting this to |
|Setting tags in key:value format separated by a space lets you further understand your data in New Relic. For example identifying different test runs or machines running the tests. In the docker command add: |
|Setting this to |
As your k6 test is running, k6 is sending performance metrics to the New Relic StatsD integration which in turn is sending these metrics to the New Relic Telemetry Data Platform. These will be prefixed with
k6. so you can identify them.
You can visualize the metrics sent from this integration in the data explorer in the top right of New Relic (query your data).
Here are some example NRQL queries you can easily copy and paste into widgets in a New Relic dashboard, you can however stick with the chart builder. Find all your k6 Metrics under the metrics tab, prefixed with
Number of Virtual Users
SELECT latest(k6.vus) FROM Metric TIMESERIES
90th Percentile Request Duration
SELECT sum(k6.http_req_duration.sum.percentiles) AS '90th' FROM Metric WHERE percentile = 90 TIMESERIES
Max, Average, Median Request Duration Duration
SELECT max(k6.http_req_duration.summary) AS 'Max Duration', average(k6.http_req_duration.median) AS 'Median', average(k6.http_req_duration.mean) AS 'Avg' FROM Metric TIMESERIES
Rate of Requests
SELECT rate(max(k6.http_reqs.per_second), 1 seconds) FROM Metric TIMESERIES
Data Sent and Data Received
SELECT sum(k6.data_received) as 'Data Received', max(k6.data_sent) AS 'Data Sent' FROM Metric TIMESERIES
Histogram bucketing Requests
SELECT histogram(`k6.http_reqs`, 80, 20) FROM Metric
Change in the number of Requests
SELECT derivative(k6.http_reqs, 30 seconds) AS 'Rate /reqs' FROM Metric TIMESERIES
Scrolling List of all k6 Performance Metrics
SELECT uniques(metricName) FROM Metric WHERE metricName LIKE 'k6%' LIMIT MAX