Cloud Monitoring and Cloud Logging: Metrics, Dashboards, Alerting Policies, Log Analytics and Sinks

Google Cloud Platform Architect 55 min min read Updated: Nov 17, 2026 Intermediate
Cloud Monitoring and Cloud Logging: Metrics, Dashboards, Alerting Policies, Log Analytics and Sinks
Intermediate Topic 1 of 3

Observability Pillars

PillarQuestionGCP tool
MetricsHow is it performing?Cloud Monitoring
LogsWhat happened?Cloud Logging
TracesWhere is the time spent?Cloud Trace
Errors and profilesWhat is breaking and which code is slow?Error Reporting, Cloud Profiler

Cloud Monitoring

  • Collects metrics from Google services automatically (CPU, requests, latency, disk)
  • VMs need the Ops Agent for memory, disk usage, process and application logs/metrics
  • Metrics scope lets one project view metrics from many projects
  • Dashboards (custom or built-in) and Metrics Explorer (build charts with MQL or PromQL)
  • Managed Service for Prometheus for Kubernetes and Prometheus metrics
bash # Install the Ops Agent on a Debian VM curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh sudo bash add-google-cloud-ops-agent-repo.sh --also-install sudo systemctl status google-cloud-ops-agent"*"

Alerting

  • An alerting policy has a condition (for example CPU above 80 percent for 5 minutes), notification channels and documentation for responders
  • Channels: email, SMS, mobile app, Slack, PagerDuty, webhooks, Pub/Sub
  • Uptime checks probe a URL or TCP port from several locations and alert on failure
  • Alert on symptoms users feel (error rate, latency) and on saturation (disk, queue age)
  • Use SLO-based alerts (burn rate) for services with objectives
bash gcloud monitoring channels create --display-name="Ops email" --type=email --channel-labels=email_address=ops@example.com cat > policy.yaml <<'EOF' displayName: High CPU on web VMs combiner: OR conditions: - displayName: CPU above 80% for 5 min conditionThreshold: filter: 'metric.type="compute.googleapis.com/instance/cpu/utilization" AND resource.type="gce_instance"' comparison: COMPARISON_GT thresholdValue: 0.8 duration: 300s aggregations: [{alignmentPeriod: 60s, perSeriesAligner: ALIGN_MEAN}] EOF gcloud alpha monitoring policies create --policy-from-file=policy.yaml --notification-channels=CHANNEL_ID

Cloud Logging

  • Collects logs from Google services, VMs (Ops Agent), GKE, Cloud Run and your apps. Write structured JSON logs for easy filtering
  • Query in Logs Explorer with the Logging query language
  • Log buckets store logs with a retention period (_Default 30 days, _Required 400 days for audit logs)
  • Log Analytics lets you run SQL on logs and link them to BigQuery
bash gcloud logging read 'resource.type="cloud_run_revision" AND severity>=ERROR' --limit=10 --freshness=1h gcloud logging write app-log '{"event":"checkout","status":"failed","orderId":42}' --payload-type=json --severity=ERROR

Log Router and Sinks

text Log entries ─► Log Router ─► _Default bucket (search, 30 days) ├─► Sink: BigQuery (analysis) ├─► Sink: Cloud Storage (cheap long-term archive, compliance) ├─► Sink: Pub/Sub (stream to SIEM or other tools) └─► Exclusion filters (drop noisy logs to save cost)
bash gcloud logging sinks create audit-to-bq bigquery.googleapis.com/projects/sec-proj/datasets/audit --log-filter='logName:"cloudaudit.googleapis.com"' --include-children --organization=987654321 gcloud logging metrics create checkout_errors --description="Failed checkouts" --log-filter='jsonPayload.event="checkout" AND jsonPayload.status="failed"'
  • Log-based metrics turn log patterns into metrics you can chart and alert on
  • Use aggregated sinks at the organization level and send to a central security project
  • Control cost with exclusion filters and shorter retention for debug logs

Best Practices

  1. Install the Ops Agent on every VM
  2. Use structured logs with severity and request IDs
  3. Create dashboards per application and one for the whole platform
  4. Alert on user-facing symptoms, with documentation links
  5. Centralize audit logs and keep them immutable
  6. Review costs from logs and metrics monthly

Practice

  1. Install the Ops Agent and view memory metrics
  2. Create an alert for high CPU and test it
  3. Write a log entry and find it in Logs Explorer
  4. Create a sink that exports errors to BigQuery
  5. Build a dashboard with CPU, requests and error rate

Conclusion

Cloud Monitoring collects metrics and alerts, Cloud Logging collects and routes logs, and the Ops Agent covers VMs. Use uptime checks, SLO-aware alerts, sinks for retention and analysis, and structured logs.

Quick Summary: pillars; Monitoring; alerting; Logging; router; practices.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators