This guide covers running the CloudWatch integration and visualizing the results:
- Run the CloudWatch agent
- Run the k6 test
- Visualize k6 metrics in Amazon CloudWatch
We presume that you already have a machine that supports both running k6 and CloudWatch agent, which either runs a flavor of GNU/Linux or Windows. Just go ahead and download the suitable CloudWatch agent version for your operating system.
Create an IAM role to be able to send metrics to CloudWatch via the agent. Then, if you are running on Amazon EC2, just attach the role to your EC2 instance, so that you can be able to send metrics to CloudWatch. Otherwise, if you are running on-premises servers, follow this guide.
Download the CloudWatch Agent package suitable for your operating system. For example, on Debian 10 (Buster), we've used the following link. For other operating systems, please refer to this guide:
Install the package:
Configure the agent to receive data from k6. For this, create a file called "/opt/aws/amazon-cloudwatch-agent/etc/statsd.json" and paste the following JSON config object into it. This configuration means that the agent would listen on port number 8125, which is the default port number for k6 and StatsD. The interval for collecting metrics is 5 seconds and we don't aggregate them, since we need the raw data later in CloudWatch.
Run the following command to start the agent:
You can check the status of the agent using the following command:
The following options can be configured as environment variables, depending on the agent's configuration:
|K6_STATSD_ADDR||Address of the statsd service, currently only UDP is supported. The default value is localhost:8125.|
|K6_STATSD_NAMESPACE||The namespace used as a prefix for all the metric names. The default value is k6.|
|K6_STATSD_PUSH_INTERVAL||Configure how often data batches are sent. The default value is 1s.|
|K6_STATSD_BUFFER_SIZE||The buffer size. The default value is 20.|
Visualization of the exported metrics to CloudWatch is done by creating a dashboard and selecting desired metrics to be displayed.
Here's an example dashboard we've created to visualize the test results.
The above dashboard is exported as JSON and is available here.