Created
January 19, 2026 17:23
-
-
Save craigderington/069e4f9b7e990572ca4b59929f6936b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -Eeuo pipefail | |
| URL="http://192.168.1.204:8000/api/increment" | |
| ITERATIONS=100 | |
| CONCURRENCY=50 | |
| LOGFILE="chaos.log" | |
| export URL | |
| post() { | |
| local i="$1" | |
| local start end latency | |
| start=$(date +%s%3N) | |
| if curl -fsS -X POST "$URL" \ | |
| -H 'Content-Type: application/json' \ | |
| -o /dev/null; then | |
| end=$(date +%s%3N) | |
| latency=$((end - start)) | |
| printf '%s OK %03d %4dms\n' "$(date '+%F %T')" "$i" "$latency" | |
| else | |
| end=$(date +%s%3N) | |
| latency=$((end - start)) | |
| printf '%s ERR %03d %4dms\n' "$(date '+%F %T')" "$i" "$latency" >&2 | |
| return 1 | |
| fi | |
| } | |
| export -f post | |
| run_storm() { | |
| seq 1 "$ITERATIONS" | xargs -P "$CONCURRENCY" -I {} bash -c 'post "$1"' _ {} | |
| } | |
| echo "=== CHAOS RUN $(date '+%F %T') ===" | tee -a "$LOGFILE" | |
| if ! OUTPUT=$(run_storm 2>&1 | tee -a "$LOGFILE"); then | |
| echo "⚠️ Errors detected during run" | tee -a "$LOGFILE" | |
| fi | |
| OK_COUNT=$(grep -c ' OK ' <<<"$OUTPUT" || true) | |
| ERR_COUNT=$(grep -c ' ERR ' <<<"$OUTPUT" || true) | |
| SUMMARY="$(date '+%F %T') OK=$OK_COUNT ERR=$ERR_COUNT" | |
| echo "$SUMMARY" | tee -a "$LOGFILE" | |
| echo "🔥 Storm complete — $SUMMARY" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment