Skip to content

Swiss-army-knife Docker image for testing your containerized infrastructure.

License

Notifications You must be signed in to change notification settings

epomatti/stressbox

Repository files navigation

stressbox

GitHub Workflow Status (with event) codecov Go Report Card codebeat badge

Stressbox is a small Docker utility for Cloud Engineers and SREs that conveniently assists on testing common scenarios involving containerized infrastructure.

  • Load testing - Simulate high CPU or memory usage to trigger autoscaling and alarms.
  • Stress testing - Force stress test scenarios and observe the cluster resiliency.
  • Networking/firewall - Test firewall rules and connectivity requirements within your infrastructure.

Check the Private repositories section for examples on how to deploy the image to your cluster.

Endpoints

Stressbox has a web interface. Deploy the image to your cluster and use the endpoints:

Endpoint Functionality Example
/cpu?x={n} Stresses the CPU by a factor of "x" curl 127.1:8080/cpu?x=42
/mem?add={mb} Increases the used memory in megabytes curl 127.1:8080/mem?add=100
/tcp?addr={addr} Tests a target TCP connection curl 127.1:8080/tcp?addr=google.com:443
/envs?env={var} Returns an environment variable curl 127.1:8080/envs?env=DB_NAME
/json?size={n} Returns a JSON batch of size "n" curl 127.1:8080/json?size=10000
/exit Exits the application curl 127.1:8080/exit
/log?={m} Writes to standard out curl 127.1:8080/log?m=Hello
/ Returns a static OK curl 127.1:8080/

Getting started

Running the image locally is an easy way to get to know the toolbox:

Pull the image:

docker pull ghcr.io/epomatti/stressbox

An ARM64 release is now available on Docker Hub:

docker pull epomatti/stressbox:arm64

Start the container:

💡 Add -e port=<PORT> to start the listener in another port

docker run -p 8080:8080 ghcr.io/epomatti/stressbox

Call the /cpu endpoint to simulate high CPU usage:

curl localhost:8080/cpu?x=30

The x parameter is a simple Fibonacci length, adjust to your requirements.

Load testing

Choose your favorite load testing tool. Here's an example with K6:

// script.js
import http from 'k6/http';
import { sleep } from 'k6';

const URL = __ENV.URL
console.log(`Calling ${URL}`);

export default function () {
  const res = http.get(URL);
  sleep(0);
}

Running the load testing:

k6 run -e URL="https://yourserver/cpu?x=30" --vus 10 --duration 300s script.js

Private repositories

Command samples to upload this image to your docker repository:

AWS Elastic Container Registry (ECR)

docker pull ghcr.io/epomatti/stressbox
docker tag ghcr.io/epomatti/stressbox "$account.dkr.ecr.$region.amazonaws.com/stressbox:latest"
aws ecr get-login-password --region $region | docker login --username AWS --password-stdin "$account.dkr.ecr.$region.amazonaws.com"
docker push "$account.dkr.ecr.$region.amazonaws.com/stressbox:latest"

Azure Container Registry (ACR)

az acr login --name "$acr"
docker pull ghcr.io/epomatti/stressbox
docker tag ghcr.io/epomatti/stressbox "$acr.azurecr.io/$repository:latest"
docker push "$acr.azurecr.io/$repository:latest"