Skip to content

Instantly share code, notes, and snippets.

@gspncr
Last active December 14, 2021 18:07
Show Gist options
  • Save gspncr/b2c36e01b4df35786f53abc9c731525f to your computer and use it in GitHub Desktop.
Save gspncr/b2c36e01b4df35786f53abc9c731525f to your computer and use it in GitHub Desktop.
k6 and New Relic demo stack

Assumptions: a New Relic account and Ubuntu 18. Works on a t2.micro

k6 installation instructions from their docs

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 379CE192D401AB61
echo "deb https://dl.bintray.com/loadimpact/deb stable main" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install k6

store our tests in its own directory. organisation is key 🗝

mkdir k6-tests && cd k6-tests

write a sample script and save it as script.js - k6 scripts are written in JavaScript, just like New Relic Synthetics are 😄

echo "import http from 'k6/http'; import { sleep } from 'k6'; export default function() { http.get('http://emea-partners.newrelic-es.com'); sleep(1); }" > script.js

install docker (we need it for running NR StatsD

sudo apt install docker.io -y

run the docker container: include account ID and insert API key

docker run \
  -d --restart unless-stopped \
  --name newrelic-statsd \
  -h $(hostname) \
  -e NR_ACCOUNT_ID=<NR ACCOUNT ID> \
  -e NR_API_KEY="<YOUR-INSERT-API-KEY>" \
  -p 8125:8125/udp \
  newrelic/nri-statsd:latest

If your account is in the NR EU region then also add this to the above command: -e NR_EU_REGION=true \

check the container is up and running

sudo docker ps -a

You just include --out statsd to your test run and the metrics will send automatically to NR. You don't need an agent running, that is optional.

k6 run --vus 12 --duration 30s --out statsd script.js

In New Relic you can run NRQL: from Metric select uniques(metricName) where metricName like 'k6%' to view the metrics sent from k6. You can also just discover them in the data explorer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment