GCP — alert when approaching a project quota
A GCP project quota (CPU, IPs, persistent disks) creeps toward the limit. The next terraform plan fails with RESOURCE_EXHAUSTED. Quota requests take 1–2 days — needs head start.
Recipe
#!/usr/bin/env bash
# /etc/cron.d/gcp-quota
# 0 */6 * * * root /opt/gcp-quota.sh
PROJECT=${GCP_PROJECT}
REGION=${GCP_REGION:-europe-west1}
WARN_PCT=${WARN_PCT:-80}
# Compute quota for the region
HOTSPOTS=$(gcloud compute regions describe "$REGION" --project="$PROJECT" --format=json \
| jq --argjson w "$WARN_PCT" '
[.quotas[] | select(.limit > 0 and (.usage / .limit * 100) > $w) |
{metric: .metric, used: .usage, limit: .limit,
pct: ((.usage / .limit * 100) | floor)}]')
COUNT=$(echo "$HOTSPOTS" | jq 'length')
if [ "${COUNT:-0}" -gt 0 ]; then
SUMMARY=$(echo "$HOTSPOTS" | jq -r '.[] | "\(.metric)=\(.pct)%"' | head -5 | tr '\n' ',')
curl -fsS "$HEARTBEAT_URL" --data-urlencode "quota_warn=$COUNT,examples=$SUMMARY"
exit 2
fi
echo "OK (no quotas above ${WARN_PCT}%)"
Same thing in Enterno.io
Wrap in an Enterno heartbeat — catch 80 % quota with 1–2 days lead time, time enough to open a GCP ticket.
Related recipes
An Azure subscription approaches a quota (vCPU per region, public IPs, storage accounts) — the next terraform apply fails with 429/ItemNotFound. Quota raises go via a support ticket, you need a head start.
Ensure your site returns 2xx every minute, alert to Slack/Telegram on failure.
Minimal script that checks an SSL certificate and alerts 14 days before expiry.