Open source

New Relic


The built-in StatsD output has been deprecated on k6 v0.47.0. You can continue to use this feature by using the xk6-output-statsd extension, and this guide has been updated to include instructions for how to use it.

For more information on the reason behind this change, you can follow this issue in the k6 repository.

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

Before you begin

To use the StatsD output option, you have to build a k6 binary using the xk6-output-statsd extension. For more details, refer to StatsD.

Run the New Relic StatsD integration

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 --rm \
  -d --restart unless-stopped \
  --name newrelic-statsd \
  -h $(hostname) \
  -p 8125:8125/udp \

Replace <NR-ACCOUNT-ID> with your New Relic Account ID and <NR-INSERT-API-KEY> with your New Relic Insert API Key.

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 required environment variables used in the above command are:

NR_ACCOUNT_IDThe Account ID used in New Relic You can find your account ID here.
NR_API_KEYThe 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.

Optional environment variables you can use:

NR_EU_REGIONSetting this to true tells the integration your account is housed in the New Relic EU region.
TAGSSetting 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: -e TAGS="k6Test:myExampleTest someKey:someValue" \.
NR_LOG_METRICSSetting this to true activates verbose logging for the integration.

About the New Relic integration

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.

Run the k6 test

Once the integration is running, run the k6 test and send the metrics to the integration with:

$ K6_STATSD_ENABLE_TAGS=true k6 run --out output-statsd script.js

Make sure you’re using the k6 binary you built with the xk6-output-statsd extension.

You can look at the StatsD output page for configuration options.

Visualisation in New Relic

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.

k6 metrics as seen in the New Relic data explorer

You can visualize the metrics sent from this integration in the data explorer in the top right of New Relic (query your data).

Sample New Relic k6 dashboard

You can also add these metrics to dashboards and alert on k6 metrics.

Example NRQL Queries


New Relic doesn’t support calculating percentiles from metric data, which is the data format sent by this k6 output. See this New Relic forum post and the documentation about the metric data type for details.

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 k6.

Number of Virtual Users

SELECT latest(k6.vus) FROM Metric TIMESERIES

Max, Median, and Average Request 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), 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