Using Grafana Cloud Prometheus, you can send your k6 metrics into Grafana Cloud to better visualize your testing results, enabling you to correlate k6 metrics with other metrics of your monitored services using Grafana.
While this article focuses on Grafana Cloud, any remote-write capable Prometheus installation is compatible with this approach.
If you do not have a Grafana Cloud account, you can sign up here. The free plan includes 10,000 Prometheus series.
Now, you need the URL, username and password of your Grafana Cloud Prometheus instance to configure the integration.
Log in to Grafana.com and visit the Cloud Portal. Click on the Details button of your Prometheus service.
Copy the URL of the Remote Write Endpoint and the Username / Instance ID. Create and copy an API key of MetricsPublisher role that will be used as password.
Next, we configure and run telegraf. Telegraf will collect the k6 metrics and forward them - using the Prometheus Remote Write endpoint - to Grafana Cloud Prometheus.
To install telegraf, follow the official Telegraf documentation.
Edit your telegraf.conf file using the example below. The example only requires you to change the username, password, and URL of the HTTP output to match your Grafana Cloud Prometheus settings.
You can now run the Telegraf instance as follow:
An example repository using Docker to run Telegraf is available on GitHub at https://github.com/k6io/example-k6-to-grafana-cloud.
When telegraf is running, you can execute your k6 test and configure k6 to output the metrics to the telegraf instance. Telegraf will forward the k6 metrics to your Grafana Cloud Prometheus.
In Grafana Cloud, click on the Explore icon on the menu bar, and choose the Prometheus data source from the dropdown in the top left. In the query field, query k6 metrics to explore your testing results.