Alert when CDN cache-hit ratio drops
The CDN cache_status header (cf-cache-status or x-cache) suddenly returns MISS on more than 30% of requests — origin load + bandwidth bills both spike.
Recipe
#!/usr/bin/env bash
# Sample cache_status header N times, alert if MISS rate > THRESHOLD.
URL=${1:?URL required}
N=${N:-20}
THRESHOLD_PERCENT=${THRESHOLD_PERCENT:-30}
MISS=0
for i in $(seq 1 "$N"); do
STATUS=$(curl -sI "$URL?nocache=$RANDOM" | awk -F': ' '
/^cf-cache-status:|^x-cache:/ { print toupper($2) }
' | tr -d '\r')
case "$STATUS" in *MISS*|*EXPIRED*|*BYPASS*) MISS=$((MISS+1));; esac
done
PCT=$((MISS * 100 / N))
if [ "$PCT" -gt "$THRESHOLD_PERCENT" ]; then
curl -X POST "$SLACK_WEBHOOK" \
--data "{\"text\":\"CDN cache miss rate: $PCT% on $URL\"}"
fi
Same thing in Enterno.io
This is the "roll your own bot" approach. The Enterno HTTP monitor already stores response headers — Pioneer+ surfaces cache-hit ratio on the dashboard and alerts without a bash loop.
Related recipes
Memcached fills up and starts evicting keys under load; the app cache-misses and hammers the DB. Want an evictions/min threshold.
A Worker auto-deploys from main. Once prod 5xx rate jumped to 12% — but dashboards get checked once a day. Want a per-minute probe.
A CloudFront distribution started serving 5xx 4 % of the time — far-region clients see broken pages. CloudWatch graph exists; dashboard goes unwatched.