No results for

Powered byAlgolia

Grafana Cloud

sugerir editar

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.

Prerequisites

Configuration

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.

Grafana Cloud Portal

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.

Create API Key

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.

telegraf.conf
1[agent]
2 interval = "10s"
3 round_interval = true
4 metric_batch_size = 5000
5 metric_buffer_limit = 100000
6 collection_jitter = "0s"
7 flush_interval = "1s"
8 flush_jitter = "0s"
9 precision = ""
10 debug = true
11 logtarget = "stderr"
12 hostname = ""
13 omit_hostname = false
14
15[[outputs.http]]
16 url = "https://prometheus-us-central1.grafana.net/api/prom/push" # <--
17 method = "POST"
18 username = "Prometheus username or Instance ID" # <--
19 password = "Grafana API Key (MetricsPublisher role)" # <--
20 data_format = "prometheusremotewrite"
21
22[outputs.http.headers]
23 Content-Type = "application/x-protobuf"
24 Content-Encoding = "snappy"
25 X-Prometheus-Remote-Write-Version = "0.1.0"
26
27[[inputs.influxdb_listener]]
28 service_address = ":8186"
29 read_timeout = "10s"
30 write_timeout = "10s"
31 max_body_size = "32MiB"
32 name_prefix = "k6_"

You can now run the Telegraf instance as follow:

telegraf -config $PATH/telegraf.conf

An example repository using Docker to run Telegraf is available on GitHub at https://github.com/k6io/example-k6-to-grafana-cloud.

Run the test

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.

# if telegraf is running on another machine
$ k6 run --out influxdb=http://my-telegraf-host:8186 my-test.js
# if telegraf is running on the same host and port 8186:
$ k6 run --out influxdb my-test.js

Explore k6 metrics

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.

Explore k6 metrics in Grafana Cloud