GC-301e · Module 3
Cloud Monitoring & Observability
3 min read
Cloud Monitoring integration through Gemini CLI transforms observability from dashboard-watching into conversational investigation. Instead of navigating the Cloud Console to build monitoring queries, describe what you want to observe: "Show me p99 latency for my-api over the last 6 hours, broken down by revision." Gemini translates this into the correct Monitoring Query Language (MQL) or PromQL expression, executes it, and presents the results. The investigation continues conversationally: "Compare that to the same period last week. Is the latency regression correlated with the deployment at 2pm?"
Alert policy management through Gemini CLI is where operational efficiency compounds. Creating a monitoring alert in the Cloud Console requires navigating multiple forms, selecting metrics, configuring thresholds, and setting notification channels. Through Gemini CLI: "Create an alert that fires when Cloud Run error rate exceeds 5% for more than 5 minutes, notify the ops-team Slack channel." Gemini generates the alert policy JSON, creates it via the API, and verifies the notification channel is correctly configured.
# Query Cloud Monitoring via Gemini CLI
# "Show me error rates for the last 6 hours"
gcloud monitoring metrics list \
--filter="metric.type=run.googleapis.com/request_count" \
--format json
# Create an alert policy
# Gemini generates this from: "Alert on >5% error rate for 5 minutes"
gcloud monitoring policies create --policy-from-file=alert.json
# alert.json (generated by Gemini):
# {
# "displayName": "Cloud Run Error Rate > 5%",
# "conditions": [{
# "displayName": "Error rate threshold",
# "conditionThreshold": {
# "filter": "resource.type=\"cloud_run_revision\" AND metric.type=\"run.googleapis.com/request_count\" AND metric.labels.response_code_class!=\"2xx\"",
# "comparison": "COMPARISON_GT",
# "thresholdValue": 0.05,
# "duration": "300s"
# }
# }],
# "notificationChannels": ["projects/my-project/notificationChannels/12345"]
# }
# Log-based investigation
# "Show me the error logs from Cloud Run in the last hour"
gcloud logging read \
"resource.type=cloud_run_revision AND severity>=ERROR" \
--limit 50 --format json