Implementing observability practices and troubleshooting issues · Topic 2 of 6
Collecting Metrics, Managed Prometheus, Synthetic Monitors and Custom Metrics
Collect metrics from apps, platforms and networks, use Managed Service for Prometheus, probe endpoints with synthetic monitors and build log-based metrics.
- 5 min
- Platform metrics are automatic; VM memory and disk need the Ops Agent.
- Managed Service for Prometheus: PodMonitoring on GKE, self-deployed collection elsewhere, PromQL everywhere.
- Uptime checks test availability; synthetic monitors test whole user journeys.
What it is
Cloud Monitoring stores time series metrics: numbers measured over time, with labels. Google Cloud services publish many metrics automatically, but application metrics, VM memory and disk, Prometheus metrics and business counters need extra setup.
Metrics only show what happens when users or traffic arrive. Synthetic monitors and uptime checks probe endpoints on a schedule, so you find failures before users do.
How it works
Sources of metrics
| Source | How you get the metrics |
|---|---|
| Google Cloud services | Collected automatically, such as Cloud Run request counts and load balancer latency |
| Compute Engine VMs | CPU and network are automatic; memory, disk usage and process metrics need the Ops Agent |
| Applications | OpenTelemetry metrics, Prometheus metrics, or the Cloud Monitoring API |
| GKE | System metrics automatically; workload metrics with Managed Service for Prometheus |
| Networking | VPC Flow Logs, load balancer and Cloud NAT metrics, Network Intelligence Center |
| Cloud Service Mesh | Request count, latency and errors between services from the mesh proxies |
| Hybrid and multi-cloud | Managed Service for Prometheus self-deployed collection or OpenTelemetry collectors running outside Google Cloud |
Google Cloud Managed Service for Prometheus
Managed Service for Prometheus collects Prometheus metrics and stores them in Google's global, managed backend. You keep Prometheus exporters, PromQL queries and Grafana, without running Prometheus servers or worrying about storage scale.
| Collection mode | How |
|---|---|
| Managed collection | Google-managed collectors on GKE, configured with PodMonitoring resources |
| Self-deployed collection | Run a Google-built Prometheus binary where you already run Prometheus, including outside Google Cloud |
| OpenTelemetry | An OTel collector exporting Prometheus-style metrics |
apiVersion: monitoring.googleapis.com/v1
kind: PodMonitoring
metadata:
name: web
namespace: shop
spec:
selector:
matchLabels:
app: web
endpoints:
- port: metrics
interval: 30s
Queries use PromQL in Cloud Monitoring, in Grafana or in alerting policies. Cost depends on the number of samples ingested, so a longer scrape interval costs less.
Synthetic monitoring and uptime checks
| Probe | What it does | Use |
|---|---|---|
| Uptime check | Sends HTTP, HTTPS or TCP requests from several locations and checks the response | Is the endpoint up and responding correctly |
| Private uptime check | Probes internal endpoints through Service Directory | Internal services with no public address |
| Synthetic monitor | Runs your test code on a schedule in a Cloud Run function, for example a Mocha test or a broken link checker | Multi-step user journeys such as login then checkout |
Each probe produces metrics, and you alert on failures. Synthetic monitors catch problems such as a broken login flow that a simple health endpoint would still report as up.
Custom metrics
When no existing metric measures what you need, such as orders processed or queue depth, write a custom metric with the Cloud Monitoring API or through OpenTelemetry. API-written custom metrics use the custom.googleapis.com/ prefix.
Keep label cardinality low. A label such as user ID creates a separate time series per user, which increases cost and slows queries.
Log-based metrics
A log-based metric turns matching log entries into a metric, with no code change.
| Type | Measures |
|---|---|
| Counter | How many entries match the filter |
| Distribution | Values extracted from entries, such as a latency field, as a histogram |
gcloud logging metrics create checkout_errors \
--description="Checkout errors" \
--log-filter='resource.type="k8s_container" AND severity>=ERROR AND jsonPayload.route="/checkout"'
Label extractors add labels from log fields, for example the error code. A log-based metric counts entries only from when it is created; it does not backfill older logs.
A worked example
An online shop runs on GKE, with a legacy order service on VMs. The SRE team installs the Ops Agent on the VMs for memory and disk metrics, and enables Managed Service for Prometheus managed collection with a PodMonitoring for each service's metrics port.
A synthetic monitor runs the login and checkout journey every five minutes. A log-based counter tracks payment declines from structured logs, and alerts fire on synthetic failures and on spikes in declines.
How the exam asks about this
- "VM memory utilization is missing from Cloud Monitoring." Install the Ops Agent on the VMs.
- "The team uses Prometheus exporters and PromQL and wants a managed backend for many GKE clusters." Use Managed Service for Prometheus with managed collection.
- "Alert when a multi-step checkout flow breaks, even at night with no users." Create a synthetic monitor for the journey and alert on its failures.
What to remember for the exam
- Platform metrics are automatic; VM memory and disk need the Ops Agent.
- Managed Service for Prometheus: PodMonitoring on GKE, self-deployed collection elsewhere, PromQL everywhere.
- Uptime checks test availability; synthetic monitors test whole user journeys.
- Custom metrics for business values; keep label cardinality low.
- Log-based metrics count or measure matching logs from creation time onward.
A health check endpoint that returns 200 does not prove the service works for users. Pair it with synthetic monitors that exercise the real user journey.
Common mistakes
Running self-managed Prometheus servers per cluster for long-term storage. Scaling and retention become your problem. Use Managed Service for Prometheus.
Using high-cardinality labels. Per-user or per-request labels multiply time series and cost. Use bounded values.
Expecting a new log-based metric to show history. It starts counting when created. Use Log Analytics for past data.
Check yourself
Which Kubernetes resource tells Managed Service for Prometheus what to scrape?
A PodMonitoring resource, which selects pods by label and names the metrics port and scrape interval.
What is the difference between an uptime check and a synthetic monitor?
An uptime check sends a simple request to an endpoint, while a synthetic monitor runs your own test code to exercise a multi-step user journey.
When should you use a distribution log-based metric?
When you need the spread of a numeric value from logs, such as request latency, rather than just a count of matching entries.
Topic 2 of 6 in Implementing observability practices and troubleshooting issues
Test yourself on Implementing observability practices and troubleshooting issues
The full Google Cloud Professional Cloud DevOps Engineer question bank has 751 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Google Cloud. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.