Interview Prep/Monitoring & Observability/Rapid-Fire PromQL & LogQL

LogQL: rate of 4xx responses per path from unstructured NGINX access logs?

AdvancedProductionRapid-Fire PromQL & LogQL
Answer
sum by (path) (rate(
  {app="ingress-nginx"}
  | pattern "<ip> - <_> [<_>] \"<method> <path> <_>\" <status> <size> <_>"
  | status >= 400 | status < 500 [5m]))

The pattern parser is faster and easier to read than regexp for fixed-format lines. Watch cardinality: if path contains IDs, normalise it with label_format or group by a coarser label.

All Monitoring & Observability questions Roadmap: Monitoring & alerting

More on Rapid-Fire PromQL & LogQL