Chapter 87: Prometheus and Grafana Monitoring
87.1 Why metrics — the silent CPU saturation story
Story. At a Flipkart-style checkout team in Bengaluru, Friday Big Billion Night traffic rose. CPU on pay-api sat at 95% for forty minutes. No page was red. No pager fired. Orders still returned 200, but latency climbed from 120 ms to 2.8 s. Customers abandoned carts. The weekend loss was about ₹2.4 lakh in abandoned checkouts. Priya opened Grafana only after support called. The graph was already a cliff. They added a PromQL alert on CPU and p95 latency. Next sale, the pager rang at 70% CPU. That is why metrics matter: numbers over time catch pain before the outage ticket.
Why
Logs tell stories after something breaks. Metrics show a trend while it is still rising. You need both, but metrics are how you notice saturation early.
What
- Metric — A named number with labels and a timestamp (for example
cpu_usagefor podpay-api). - Time series — The same metric sampled again and again over time.
- Saturation — A resource is almost full (CPU, memory, disk, queue).
- Latency — How long a request takes.
- Alert — A message when a PromQL condition stays true long enough.
How
- Collect host and app metrics on a fixed interval (often 15–30 seconds).
- Store them in a time-series database.
- Graph the four golden signals: latency, traffic, errors, saturation.
- Alert on burn, not on every tiny spike.
Example 1: Load average on a hot node
uptime
Output
21:14:02 up 12 days, 3:01, 2 users, load average: 7.82, 6.41, 3.10
What it shows: One-minute load is 7.82 on a machine that may only have 4 CPUs. The box is saturated. Without a metric history you only see this when you SSH in late.
Example 2: Same pain as a Prometheus instant query
100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
Output (Prometheus UI)
{instance="ip-10-0-1-23:9100"} 94.6
What it shows: About 95% CPU used on that instance over five minutes. This is the number that should have paged Priya.
Ravindra Bagale's Tip
Alert on sustained saturation and latency, not on a one-second blip. A five-minute window saves sleep.
एका सेकंदाच्या spike वर नव्हे — sustained saturation आणि latency वर alert. पाच मिनिटांची window झोप वाचवते.
एक सेकंड के spike पर नहीं — sustained saturation और latency पर alert. पाँच मिनट की window नींद बचाती है.
Quick quiz
Q1. What is a metric?
A named number with labels and a time, collected again and again.
Q2. Why did the Flipkart-style team lose money?
CPU saturation raised latency; no alert fired until customers left.
Q3. Name one golden signal.
Latency, traffic, errors or saturation.
Did you understand? Let us try it once more.