Using the InfluxDB extension, you can store k6 metrics in InfluxDB v2.0 and analyze your performance results with Grafana or other tools.
Build the k6 version
To build a k6 binary with the extension, first, ensure you have installed Go and Git; the following steps are:
xk6 will create the k6 binary in the local folder.
To learn more about how to build custom k6 versions, check out xk6
Run the test
Check that the InfluxDB instance to store the k6 metrics is running.
Use the previous k6 binary and run the test passing the following options:
k6 runs the test script and sends the k6 metrics in real-time to the InfluxDB instance. You can now select the bucket to query and visualize the stored k6 metrics, for example, using the InfluxDB Data Explorer.
Here is the full list of options that can be configured and passed to the extension:
|K6_INFLUXDB_ORGANIZATION||Your InfluxDB organization ID. View organizations.|
|K6_INFLUXDB_BUCKET||The bucket to store k6 metrics data. Manage buckets.|
|K6_INFLUXDB_TOKEN||An API token that provides authorized access to store data. Manage API tokens.|
|K6_INFLUXDB_ADDR||http://localhost:8086||The address of the InfluxDB instance.|
|K6_INFLUXDB_PUSH_INTERVAL||1s||The flush's frequency of the k6 metrics.|
|K6_INFLUXDB_CONCURRENT_WRITES||4||Number of concurrent requests for flushing data. It is useful when a request takes more than the expected time (more than flush interval).|
|K6_INFLUXDB_TAGS_AS_FIELDS||vu:int,iter:int,url||A comma-separated string to set k6 metrics as non-indexable fields (instead of tags). An optional type can be specified using :type as in vu:int will make the field integer. The possible field types are int, bool, float and string, which is the default. Example: vu:int,iter:int,url:string,event_time:int.|
|K6_INFLUXDB_INSECURE||false||When true, it will skip https certificate verification.|
|K6_INFLUXDB_PRECISION||1ns||The timestamp Precision.|
You can use Grafana to query and visualize data from an InfluxDB instance. The instructions are available on InfluxDB and Grafana.
You can also build a custom Grafana dashboard to visualize the testing results in your own way.
For testing purposes, the influxdb extension repository includes a docker-compose setup with two basic dashboards.