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