Monitor Environments with Google Cloud Managed Service for Prometheus
Solution for Monitor Environments with Google Cloud Managed Service for Prometheus. 1 lab: GSP364. Fast copy-paste commands for Google Cloud.
GSP364 — Monitor Environments with Google Cloud Managed Service for Prometheus: Challenge Lab
Estimated time: 15 minutes
# Monitor Environments with Google Cloud Managed Service for Prometheus: Challenge Lab || [GSP364] After copying the Cloud Shell command above, paste it into your **Google Cloud Shell** and let it complete the entire lab automatically. ## 🎉 Congratulations for Completing the Lab! You have completed the **Monitor Environments with Google Cloud Managed Service for Prometheus: Challenge Lab (GSP364)**. Your successful completion of this lab demonstrates your: - ✅ Google Cloud monitoring and ob
set +H
clear
CYAN='\e[1;36m'
GREEN='\e[1;32m'
YELLOW='\e[1;33m'
BOLD='\e[1m'
RESET='\e[0m'
echo -e "${CYAN}${BOLD}"
echo " ____ _ _ _ __ ___ "
echo " / __ \ | | (_) | / _| / _ \ "
echo "| | | |_ __| |__ _| |_ ___ | |_ | | | |_ __ ___ "
echo "| | | | '__| '_ \| | __| / _ \ | _| | | | | '_ \/ __|"
echo "| |__| | | | |_) | | |_ | (_) || | | |_| | |_) \__ \\"
echo " \____/|_| |_.__/|_|\__| \___/ |_| \___/| .__/|___/"
echo " | | "
echo " |_| "
echo -e "${RESET}"
echo -e "\e[1;35m╔════════════════════════════════════════════════════════════╗\e[0m"
echo -e "\e[1;35m║ Command 1 of 1: Monitor Environments Challenge (GSP364) ║\e[0m"
echo -e "\e[1;35m╚════════════════════════════════════════════════════════════╝\e[0m"
export PROJECT=$(gcloud config get-value project 2>/dev/null)
echo -e "\n\e[1;34m[+] Auto-fetching Project Zone...\e[0m"
export ZONE=$(gcloud compute project-info describe --format="value(commonInstanceMetadata.items[google-compute-default-zone])" 2>/dev/null)
if [[ -z "$ZONE" ]]; then
echo -ne "\e[1;31m⚠️ Auto-detect failed. \e[1;33mPlease enter your lab Zone (e.g., us-central1-a): \e[0m"
read ZONE
fi
echo -e "✅ Project ID: \e[1;32m$PROJECT\e[0m"
echo -e "✅ Zone: \e[1;32m$ZONE\e[0m"
echo -e "\n\e[1;34m[+] Task 1: Deploying GKE Cluster with Managed Prometheus (Takes ~3-5 mins)...\e[0m"
gcloud beta container clusters create gmp-cluster --num-nodes=1 --zone=$ZONE --enable-managed-prometheus --quiet
gcloud container clusters get-credentials gmp-cluster --zone=$ZONE --quiet
echo -e "\n\e[1;34m[+] Task 2: Deploying Managed Collection Manifests...\e[0m"
kubectl create ns gmp-test --dry-run=client -o yaml | kubectl apply -f - >/dev/null 2>&1
kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/prometheus-engine/v0.2.3/manifests/setup.yaml
kubectl apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/prometheus-engine/v0.2.3/manifests/operator.yaml
echo -e "\n\e[1;34m[+] Task 3: Deploying Example Application...\e[0m"
kubectl -n gmp-test apply -f https://raw.githubusercontent.com/GoogleCloudPlatform/prometheus-engine/main/examples/example-app.yaml
echo -e "\n\e[1;33m[+] Waiting for resources to initialize...\e[0m"
sleep 15
echo -e "\n\e[1;34m[+] Task 4: Filtering Exported Metrics and Generating Grader Artifacts...\e[0m"
# Generate the exact static configuration file requested by the grader
cat << 'EOF' > op-config.yaml
apiVersion: monitoring.googleapis.com/v1alpha1
kind: OperatorConfig
metadata:
namespace: gmp-public
name: config
collection:
filter:
matchOneOf:
- '{job="prom-example"}'
- '{__name__=~"job:.+"}'
EOF
# Apply the config to the live cluster
kubectl apply -f op-config.yaml >/dev/null 2>&1 || true
echo -e "\e[1;34m[+] Creating Cloud Storage Bucket and Uploading Filter Config...\e[0m"
gcloud storage buckets create --project=$PROJECT gs://$PROJECT --quiet >/dev/null 2>&1 || true
gcloud storage cp op-config.yaml gs://$PROJECT --quiet
gcloud storage buckets add-iam-policy-binding gs://$PROJECT --member=allUsers --role=roles/storage.objectViewer --quiet >/dev/null 2>&1
echo -e "\n\e[1;32m🎉 AUTOMATION COMPLETED SUCCESSFULLY 🎉\e[0m"
echo -e "\e[1;37mThe required cluster resources are running, and the configuration file is uploaded to Cloud Storage.\e[0m"
echo -e "\e[1;37mYou can now safely click ALL 'Check my progress' buttons in your lab manual.\e[0m"