The few metrics that matter
Logs are records of events; metrics are numbers sampled over time, cheap to keep and fast to chart. GCP collects most of them automatically, at no charge for Google's own services. For a web platform, four "golden signals" measured at the front door cover most of what users feel:
| # | Golden signal | Question | Metric (Cloud Monitoring) |
|---|---|---|---|
| 1 | Traffic | How busy are we? | loadbalancing.googleapis.com/https/request_count |
| 2 | Errors | What share of requests fail? | The same, split by response_code_class (5xx divided by all) |
| 3 | Latency | How slow are the slow requests? | https/total_latencies, at the 95th and 99th percentile, not the average |
| 4 | Saturation | How close to a limit are we? | Cloud Run container/instance_count against max instances, Cloud SQL connections, NAT ports |
Below the front door, a handful of metrics catch the network failures from this course before users report them:
| # | Metric | Catches | Chapter |
|---|---|---|---|
| 1 | router.googleapis.com/nat/dropped_sent_packets_count (reason OUT_OF_RESOURCES) | PayGate calls failing because NAT ports ran out | 7 |
| 2 | cloudsql.googleapis.com/database/postgresql/num_backends | Connections approaching the database's limit | 9 |
| 3 | run.googleapis.com/container/instance_count | kade-api pinned at max instances, so requests queue | 10 |
| 4 | loadbalancing.googleapis.com/https/backend_latencies | Slowness inside kade-api rather than on the way to it | 12 |
| 5 | compute.googleapis.com/instance_group/size against the target size | A managed instance group stuck below its size: a boot loop or a quota (chapter 12.2) | 12.2 |
| 6 | agent.googleapis.com/memory/percent_used (needs the Ops Agent) | VMs running out of memory before they crash | 16.1 |
| 7 | vpn.googleapis.com/tunnel_established | A VPN tunnel down (the other carries on, so nobody notices) | 15 |
One dashboard: "is the platform healthy?"
One page, read top-left to bottom-right, that answers the question in ten seconds. Each panel is one metric from section 01:
Top row: what shoppers feel. Bottom row: how close to a limit. Dashed red: the alert threshold. Dotted: 14:00.
Uptime checks: is the shop reachable from outside?
An uptime check calls a URL from several places around the world every minute or few, and records whether the right answer came back. It is the closest thing to a shopper trying the site, and it works even when no shopper is online. It can also warn before the certificate expires.
Kadé's front door now has Cloudflare and an origin lock (chapter 13), and both will treat a robot from Google's data centres with suspicion. Pick what to check, and see what blocks it:
Check passes: the whole front door works
The checker calls https://api.kade.lk/v1/health exactly like a shopper: Cloudflare, the load balancer, Cloud Armor (the request carries Kadé's secret header because it came through Kadé's zone), then Cloud Run. If any hop fails, the check fails. That is what you want: it tests the whole front door.
Show as config
URL: https://api.kade.lk/v1/health Regions: asia-pacific, europe, usa-oregon Expect: HTTP 200, body contains "ok" Also: alert if the certificate expires within 14 days
Alerts that people do not learn to ignore
An alert that fires for nothing teaches you to ignore alerts. Three habits keep them meaningful:
| # | Habit | Why |
|---|---|---|
| 1 | Alert on symptoms users feel | "5% of requests fail" is something to act on. "CPU at 80%" often is not |
| 2 | Use ratios, not counts | 50 errors in a minute is a disaster at 100 requests and nothing at 100,000. The error ratio stays meaningful as traffic grows |
| 3 | Require a duration | "Above the threshold for 5 minutes" ignores single spikes. The chart below shows the difference |
The one-minute spike at 10 minutes (a deploy, a single bad client) fires an alert, then clears by itself. The real problem at 24 minutes fires too. Get a few of the first kind a week and you start ignoring both.
Show as config
Condition: loadbalancing.googleapis.com/https/request_count, 5xx / all Threshold: > 2% Duration: 5 minutes (the "for" window)
Kadé's alert set. Few enough that each one gets attention:
| # | Alert | Condition | Sends to |
|---|---|---|---|
| 1 | Shop unreachable | Uptime check failing from 2 or more regions for 2 minutes | phone |
| 2 | Errors high | Load balancer 5xx above 2% of requests for 5 minutes | phone |
| 3 | Slow | p95 total latency above 1.5 s for 10 minutes | phone |
| 4 | Payments at risk | NAT drops with OUT_OF_RESOURCES above 0 for 5 minutes | phone |
| 5 | Database near its limit | Connections above 80% of max for 10 minutes | email / chat |
| 6 | VPN tunnel down | Either tunnel not established for 5 minutes | email / chat |
| 7 | Certificate expiring | Uptime check: certificate expires within 14 days | email / chat |
| 8 | Attack in progress | Cloud Armor denies 10 times above normal for 15 minutes (log-based metric) | email / chat |
Network Intelligence Center
Google's network troubleshooting tools, in one place in the console. They work from configuration and Google's own measurements, so most need no logs:
| # | Tool | Answers | When to use it |
|---|---|---|---|
| 1 | Connectivity Tests | "Can A reach B on this port, and if not, which rule or route stops it?" | Before and after every firewall or route change, and first in any "can't connect" incident |
| 2 | Network Topology | A live map of networks, subnets, load balancers and the traffic between them | Understanding an unfamiliar project |
| 3 | Network Analyzer | Problems it finds by itself: unused reserved IPs, subnets running out of addresses, risky configurations | A weekly glance |
| 4 | Firewall Insights | Shadowed, unused and overly broad firewall rules | Monthly clean-up (chapter 5.2) |
| 5 | Performance Dashboard | Packet loss and latency between zones and regions, and to the internet, measured by Google | "Is it us or is it Google?" |
| 6 | Flow Analyzer | Queries over VPC Flow Logs without writing SQL | "Top talkers" from a subnet |
A Connectivity Test traces a pretend packet through every check this course covered, using the real configuration, without sending anything. Two tests from Kadé:
- StartVM kade-worker 10.10.1.20 in sn-app
- Egress firewallimplied allow egress (65535)
- Route10.10.32.0/20 via peering servicenetworking-googleapis-com
- Forwardinto Google's service network
- DeliverCloud SQL kade-sql 10.10.32.3:5432
Result: REACHABLE
Every check passes, and the test names the exact route it used. Saved, it becomes a one-click check after any change to routes, peering or firewall.
Troubleshooting routines
For each common symptom, the order of steps that finds the cause fastest. Each step has the check, what the result means, and where it leads next:
- 1.
Is it only us?
Uptime check results by region; Cloudflare status page
What the result means: All regions failing: likely the whole front door. One region: a local internet problem, usually not yours.
Next: If all regions fail, go to step 2.
- 2.
Does Cloudflare reach the origin?
curl -sI https://api.kade.lk/v1/health (look for a 52x code)
What the result means: A 52x page means Cloudflare is up but the origin leg failed. Read the code with chapter 13's error decoder.
Next: No 52x but nothing loads: check DNS (dig +short api.kade.lk) and Cloudflare. A 52x: step 3.
- 3.
What does the load balancer say?
Logs: resource.type="http_load_balancer" httpRequest.status>=500, read statusDetails
What the result means: failed_to_pick_backend: no backend. denied_by_security_policy: Cloud Armor. Nothing logged at all: requests are not reaching the LB (origin lock, certificate, forwarding rule).
Next: No backend: step 4.
- 4.
Is kade-api serving?
gcloud run revisions list --service=kade-api --region=asia-southeast1
What the result means: The latest revision not ready, or failing to start, means a bad deploy.
Next: Roll back: gcloud run services update-traffic kade-api --to-revisions=LAST_GOOD_REVISION_NAME=100
Rollout plan
For a platform that has none of this today, in order of value for effort. Each stage is useful on its own, so stopping early still leaves you better off:
1.Day 1
about an hour
- Load balancer logging on (100% API, 10% images)
- Uptime check on the health URL, through Cloudflare
- Alert: shop unreachable, to your phone
- Budget alert on the billing account
2.Week 1
a few hours
- Dashboard: the six panels from section 02
- Alerts: error ratio, p95 latency, NAT drops
- App logs as JSON with trace ID and CF-Ray
- Cloud NAT error logs on
3.Month 1
spread out
- Flow logs on the subnets that carry database and PayGate traffic
- Firewall rule logging + the deny-all-log rule
- Connectivity Tests saved for the key paths
- Exclusion filters and a BigQuery sink, after a week of measuring volume
4.Later
when the basics are quiet
- An SLO with burn-rate alerts instead of fixed thresholds
- Log Analytics queries for weekly security review
- Cloudflare Logpush joined to GCP logs by CF-Ray
Back to Kadé
Commands in this chapter
Commands 1 to 3 are read-only. Commands 4 to 6 change the project.
Find the IP ranges uptime checks come from
- What it shows: The source addresses of Google's uptime checkers, by region.
- What to look for: Only needed if you check the origin directly and must allow them (section 03).
gcloud monitoring uptime list-ipsRun a Connectivity Test and read the result
- What it shows: Whether kade-worker can reach Cloud SQL on 5432, and the step that decides it.
- What to look for:
REACHABLE, or the step where it saysDROPPEDand why.
gcloud network-management connectivity-tests create worker-to-sql \ --source-instance=projects/kade-prod/zones/asia-southeast1-a/instances/kade-worker \ --destination-ip-address=10.10.32.3 --destination-port=5432 --protocol=TCPgcloud network-management connectivity-tests describe worker-to-sql \ --format="yaml(reachabilityDetails.result,reachabilityDetails.traces[0].steps)"List alert policies
- What it shows: Every alert policy and whether it is enabled.
- What to look for: The eight from section 04, all enabled, each with a notification channel.
gcloud alpha monitoring policies list --format="table(displayName,enabled,notificationChannels.len())"Create an uptime check (changes the project)
- What it shows: An HTTPS check of the health URL, every minute, from three regions, expecting a 200.
- What to look for: Results in the console under Monitoring → Uptime checks within a few minutes.
gcloud monitoring uptime create kade-api-health \ --resource-type=uptime-url --resource-labels=host=api.kade.lk,project_id=kade-prod \ --protocol=https --path=/v1/health --period=1 \ --regions=asia-pacific,europe,usa-oregon --status-codes=200Count Cloud Armor denies as a metric (changes the project)
- What it shows: A log-based metric that counts denied requests, which alert 8 can watch.
- What to look for: The metric
logging.googleapis.com/user/kade_armor_deniesin Metrics Explorer after some traffic.
gcloud logging metrics create kade_armor_denies \ --description="Requests denied by Cloud Armor" \ --log-filter='resource.type="http_load_balancer" AND jsonPayload.enforcedSecurityPolicy.outcome="DENY"'Create a notification channel (changes the project)
- What it shows: An email channel for "email / chat" alerts. Phone and chat apps are added the same way, or in the console.
- What to look for: The channel's ID in the output, used when creating alert policies.
gcloud beta monitoring channels create --display-name="Kadé platform email" \ --type=email --channel-labels=email_address=platform@kade.lk