Home

Awesome

xk6-output-statsd

Provides support for real-time output of k6 test metrics to a StatsD service.

Direct support for the StatsD metrics collector will be removed from k6 in a future release. For those seeking to continue using StatsD, the functionality may be compiled into custom k6 binaries as an xk6 extension.

Build

To build a k6 binary with this extension, first ensure you have the prerequisites:

  1. Build with xk6:
xk6 build --with github.com/LeonAdato/xk6-output-statsd

This will result in a k6 binary in the current directory.

  1. Run with the just build `k6:
./k6 run -o output-statsd <script.js>

Options

The xk6-output-statsd extension supports the following configuration options:

Environment VariableDefaultDescription
K6_STATSD_ADDRlocalhost:8125Address of the statsd service, currently only UDP is supported.
K6_STATSD_NAMESPACEk6.The namespace used as a prefix for all the metric names.
K6_STATSD_PUSH_INTERVAL1sConfigure how often data batches are sent.
K6_STATSD_BUFFER_SIZE20The buffer size.
K6_STATSD_ENABLE_TAGSfalseIf true enables sending tags. Versions prior to statsd v0.9.0 did not support tags.
K6_STATSD_TAG_BLOCKLISTvu,iter,urlComma-separated list of tags that should not be sent to statsd.

Options may be specified as system environment variables as with the following:

K6_STATSD_ADDR=localhost:8125 K6_STATSD_ENABLE_TAGS=true ./k6 run -o output-statsd examples/simple.js

Testing Locally

This repository includes a docker-compose.yml file that starts Graphite backed by StatsD which can be used for testing the xk6-output-statsd extension.

:warning: This environment is intended for testing only and should not be used for production purposes.

  1. Start the docker compose environment.
    docker compose up -d
    
    Output should appear similar to the following:
    āœ” Network xk6-output-statsd_default       Created               ...    0.0s
    āœ” Container xk6-output-statsd-graphite-1  Started               ...    0.3s
    
  2. Use your custom k6 binary to run a k6 test script sending metrics to your StatsD service started ing the previous step.
    ./k6 run -o output-statsd examples/ramping-vus.js
    
  3. Open the Graphite application by accessing http://localhost:80/ to view metrics from your test similar to the following: Graphite Dashboard