Google Cloud Tutorial · Operations · Lesson 23 of 27
Cloud Logging and Cloud Monitoring
Observability on Google Cloud: logs, log buckets and sinks, audit logs, metrics, uptime checks, SLOs and alerts.
Logging
Most services send logs to Cloud Logging automatically; applications that write structured JSON to stdout get searchable fields. Each project has two log buckets:
_Required: Admin Activity and other required audit logs, kept 400 days, free._Default: everything else, kept 30 days by default.
Sinks route logs elsewhere: a custom bucket with longer retention, BigQuery for analysis, Pub/Sub for other tools, or a central project through an aggregated sink at the organisation level. Exclusion filters drop noisy logs before they're stored (and billed). Data Access audit logs (who read what) are off by default for most services; turn them on for sensitive data.
Monitoring
Cloud Monitoring collects metrics from Google Cloud services and agents, runs uptime checks from several regions, and alerts through notification channels. SLO monitoring tracks a service-level objective and alerts on burn rate, the speed at which the error budget is being spent. Managed Service for Prometheus handles Kubernetes metrics with PromQL.
slo = 0.999 # 99.9% of requests succeed over 30 days
budget = 1 - slo
for window, errors, total in [("last hour", 180, 12_000), ("last hour", 30, 12_000), ("last 6 hours", 400, 72_000)]:
error_ratio = errors / total
burn = error_ratio / budget
action = "page someone" if burn >= 14.4 else "open a ticket" if burn >= 6 else "fine"
print(f"{window:12} error ratio {error_ratio:.3%} -> burn rate {burn:5.1f}x -> {action}")
Output
last hour error ratio 1.500% -> burn rate 15.0x -> page someone last hour error ratio 0.250% -> burn rate 2.5x -> fine last 6 hours error ratio 0.556% -> burn rate 5.6x -> fine
Test yourself
Which audit logs are always on in Google Cloud?
Data Access audit logsAdmin Activity audit logsVPC Flow LogsLoad balancer logs
Show answer
Answer: Admin Activity audit logs
Admin Activity logs are always written; Data Access logs mostly need enabling.