Q: Your Prometheus server is running out of memory and crashing every few hours. How do you troubleshoot and fix this?
Prometheus OOMs almost exclusively due to High Cardinality in the metrics it scrapes or the queries being run against it.
#Observability #Observability #L3 #Monitoring #Prometheus #SRE
🎙️ Candidate Opening & Architectural Context
""Logs tell you what happened, metrics tell you where to look, and distributed traces pinpoint the exact slow component. The interviewer is testing: High cardinality, metric relabeling, Prometheus architecture.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third.""
Advertisement
🛠️ Production Runbook & Step-by-Step Resolution
1️⃣
Initial Diagnostics & Root Cause Analysis
Prometheus OOMs almost exclusively due to High Cardinality in the metrics it scrapes or the queries being run against it.
- Find High Cardinality: When it's running, query
topk(10, count by (__name__) ({__name__=~".+"}))to find which metrics have millions of series. It's often caused by developers putting unbounded variables (like user IDs, session tokens, or full URLs) into metric labels instead of bounded HTTP status codes or methods. - Mitigation: Use
metric_relabel_configsin the scrape config todropthe problematic metrics or strip the offending high-cardinality labels before ingestion. - Long-term: Talk to the developers to remove high cardinality labels. If the scale is simply huge, implement a horizontal scaling solution like Thanos or Cortex, rather than relying on a single Prometheus instance.
2️⃣
Remediation & Permanent Safeguards
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Find High Cardinality: When it's running, query topk(10, count by (__name__) ({__name__=~".+"})) to find which metrics have millio."
⚡ 60-Second Elevator Pitch Talking Points
- Find High Cardinality: When it's running, query topk(10, count by (__name__) ({__name__=~".+"})) ...
- Mitigation: Use metric_relabel_configs in the scrape config to drop the problematic metrics or st...
- Long-term: Talk to the developers to remove high cardinality labels. If the scale is simply huge,...
Advertisement