Skip to content

GCP — алерт о приближении к project-quota

GCP project quota (CPU, IPs, persistent disks) ползёт к лимиту. Следующий terraform plan сломается с RESOURCE_EXHAUSTED. Quota request требует 1-2 дня — должно быть заранее.

Рецепт

bash
#!/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}%)"

То же самое в Enterno.io

Заверните в Enterno heartbeat — поймаете 80 % quota за 1-2 дня до hard-stop, успеете открыть GCP-тикет.

Настроить API monitor → ← Все рецепты

Похожие рецепты