How do you compute an error ratio in PromQL?
BeginnerConceptPromQL & Recording Rules
Answer
sum(rate(http_requests_total{job="api",code=~"5.."}[5m]))
/
sum(rate(http_requests_total{job="api"}[5m]))
Both sides are aggregated to the same labels (none here), so the division matches. For per-service ratios, use sum by (service) on both sides. Multiply by 100 for percent only in the display, keep ratios 0–1 in rules.
More on PromQL & Recording Rules
What are the PromQL data types?BeginnerWhat label matchers does PromQL support?BeginnerExplain `rate()`.Beginner`rate()` vs `irate()`: what is the difference?IntermediateWhat does `increase()` return and why is it sometimes a non-integer?IntermediateWhy must you `rate()` before `sum()`, never the reverse?Intermediate