Code Monkey home page Code Monkey logo

locust-cloudwatch's Introduction

Locust/CloudWatch Connector

This repo contains code and a CloudFormation template to publish Locust test result metrics to AWS CloudWatch.

For more details, read this article.

The CloudFormation template

The CloudFormation template locust-cloudwatch.yml launches an EC2 instance loaded with Locust and with the custom Python module locust_cw.py, as well as a sample Locust test module. It also creates an EC2 Instance Profile with the permissions required to create log groups, log streams and publish metrics to CloudWatch.

A t2.nano is usually enough to generate some decent load, but you can always modify the template to use a different instance type.

Launch Stack

Launching a test

Login to the EC2 instance launched in the CloudFormation template. You can see its public IP either in the EC2 console, or in the Outputs tab in the CloudFormation console.

ssh -i ec2-user@

Go to the ~/locust folder.

I left the AWS region out of the code, on purpose. Therefore you have to first set the AWS region as an environment variable:

export AWS_DEFAULT_REGION=<us-east-1|us-west-2|etc.>

Typically, you would launch Locust tests with the following command:

locust --host=http://<URL to test> -f <yourlocustfile.py>

Instead, we'll launch Locust in the following way:

python locust_cw.py --host=http://<URL to test> -f <yourlocustfile.py>

You'll be able to use all supported Locust command line options.

The locust_cw.py module

The locust_cw.py module implements Locust event hooks and some utility methods that call AWS CloudWatch APIs in response to Locust event hooks. For example, each time a response result is received, the module sends the result to an internal queue, which is later used to publish to CloudWatch and CloudWatch Logs.

I implemented it this way, so it wouldn't be necessary to update a single locustfile (Python module that contains your test definition). This reduces friction to a minimum. So, if you already have locustfiles, you don't have to change them at all!

In this version, the following values are hard-coded: CW_METRICS_NAMESPACE, CW_LOGS_LOG_GROUP and CW_LOGS_LOG_STREAM. Feel free to update them as you see fit.

I also implemented this module so I wouldn't have to update any core locust components.

The locust_cw.py module calls CloudWatch APIs. The CloudWatch template creates an IAM Role and EC2 Instance Profile for this purpose, so you don't have to configure permissions manually or store AWS keys in the Locust EC2 instance.

Security Groups

The CloudFormation template creates a Security Group that is open for port 8089 (the port used by the Locust web interface). I strongly recommend you restrict access to this port based on your workstation's IP, or your VPN.

locust-cloudwatch's People

Contributors

concurrencylabs avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.