Search code examples
influxdbk6

How to authenticate to influxdb when using k6


I am using k6 for as a load testing tool and I want to write data to influxdb. It all works fine except I do not know how to send user credentials for influxdb.

Example:

./k6.exe run --out "influxdb=http://localhost:8086/stresstest" script.js --vus 10 --duration 3s

I tried to pass influxdb username and password like this, but it doesn't work

./k6.exe run --out "influxdb=http://localhost:8086/stresstest?u=<USERNAME>&p=<PASSWORD>" script.js --vus 10 --duration 3s

I do not want to disable influxdb auth!


Solution

  • You can pass them as HTTP auth in the InfluxDB URL like this: --out "influxdb=http://<username>:<password>@localhost:8086/stresstest"

    Alternatively, you could also specify them via the K6_INFLUXDB_USERNAME and K6_INFLUXDB_PASSWORD environment variables.