fix: bruk fallback defaults for PROJECT_ID og REGION i cost-audit.sh
This commit is contained in:
parent
700fda5cbb
commit
84d22773f3
|
|
@ -2,12 +2,12 @@
|
|||
# =============================================================================
|
||||
# cost-audit.sh — OSVauco billable resource snapshot
|
||||
# Read-only, safe to run anytime.
|
||||
# Usage: source .env && bash scripts/cost-audit.sh
|
||||
# Usage: bash scripts/cost-audit.sh
|
||||
# =============================================================================
|
||||
set -euo pipefail
|
||||
|
||||
: "${PROJECT_ID:?Set PROJECT_ID}"
|
||||
: "${REGION:?Set REGION}"
|
||||
PROJECT_ID="${PROJECT_ID:-propane-will-491900-m5}"
|
||||
REGION="${REGION:-us-central1}"
|
||||
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
|
|
@ -34,31 +34,33 @@ echo ""
|
|||
ANY_RISK=false
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# 1. CLOUD RUN
|
||||
# 1. CLOUD RUN (alle regioner)
|
||||
# -----------------------------------------------------------------------------
|
||||
printf "${BOLD}${CYAN} [ CLOUD RUN ]${NC} ${DIM}(scale-to-zero = no idle cost)${NC}\n"
|
||||
CR=$(gcloud run services list \
|
||||
--project="${PROJECT_ID}" \
|
||||
--region="${REGION}" \
|
||||
--format="value(name,status.url)" 2>/dev/null || true)
|
||||
for R in us-central1 europe-west1 europe-north1; do
|
||||
CR=$(gcloud run services list \
|
||||
--project="${PROJECT_ID}" \
|
||||
--region="${R}" \
|
||||
--format="value(name,status.url)" 2>/dev/null || true)
|
||||
|
||||
if [[ -z "$CR" ]]; then
|
||||
printf " ${OK} No services deployed\n"
|
||||
else
|
||||
while IFS=$'\t' read -r NAME URL; do
|
||||
MIN=$(gcloud run services describe "$NAME" \
|
||||
--project="${PROJECT_ID}" --region="${REGION}" \
|
||||
--format="value(spec.template.metadata.annotations.'autoscaling.knative.dev/minScale')" \
|
||||
2>/dev/null || echo "0")
|
||||
MIN=${MIN:-0}
|
||||
if [[ "$MIN" -gt 0 ]]; then
|
||||
printf " ${WARN} %-30s ${YELLOW}min-instances=%s (idle cost!)${NC}\n" "$NAME" "$MIN"
|
||||
ANY_RISK=true
|
||||
else
|
||||
printf " ${OK} %-30s ${DIM}scale-to-zero${NC}\n" "$NAME"
|
||||
fi
|
||||
done <<< "$CR"
|
||||
fi
|
||||
if [[ -z "$CR" ]]; then
|
||||
printf " ${OK} ${DIM}${R}: No services${NC}\n"
|
||||
else
|
||||
while IFS=$'\t' read -r NAME URL; do
|
||||
MIN=$(gcloud run services describe "$NAME" \
|
||||
--project="${PROJECT_ID}" --region="${R}" \
|
||||
--format="value(spec.template.metadata.annotations.'autoscaling.knative.dev/minScale')" \
|
||||
2>/dev/null || echo "0")
|
||||
MIN=${MIN:-0}
|
||||
if [[ "$MIN" -gt 0 ]]; then
|
||||
printf " ${WARN} %-30s ${YELLOW}min-instances=%s (idle cost!) [%s]${NC}\n" "$NAME" "$MIN" "$R"
|
||||
ANY_RISK=true
|
||||
else
|
||||
printf " ${OK} %-30s ${DIM}scale-to-zero [%s]${NC}\n" "$NAME" "$R"
|
||||
fi
|
||||
done <<< "$CR"
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
|
@ -175,7 +177,6 @@ if [[ -z "$REPOS" ]]; then
|
|||
printf " ${OK} No Artifact Registry repos\n"
|
||||
else
|
||||
while IFS=$'\t' read -r NAME FMT SIZE; do
|
||||
# sizeBytes kan være float (f.eks. 345900.5) — bruk awk for sikker MB-konvertering
|
||||
SIZE_MB=$(awk -v s="${SIZE:-0}" 'BEGIN { printf "%.1f", s / 1048576 }')
|
||||
printf " ${OK} %-28s fmt:%-8s size:${SIZE_MB} MB\n" "$NAME" "$FMT"
|
||||
done <<< "$REPOS"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user