Pcornel
Observability · Log Platforms

LogQL Queries in Loki

Cheat sheet · https://pcornel.dk/topic.php?topic=6221

Back to the Topic

Answer

LogQL is Loki's query language: a stream selector {app="api"}, line filters |= "error", parsers | json, and metric queries such as rate({...}[5m]).

Remember

Always start with a narrow stream selector (indexed labels). Filter lines before parsing. Don't make high-cardinality labels; filter extracted fields at query time.

First checks

  • {app="api"} |= "error" | json | status >= 500 — first check for this topic
  • curl -s localhost:9090/-/ready — Prometheus ready
  • curl -s 'localhost:9090/api/v1/query?query=up' — scrape targets up/down
  • promtool check config prometheus.yml — config valid

Verify in this order

stream selector → line filters → parser → label filters → aggregation

Where it usually breaks

Broad selectors over long time ranges scan huge amounts of data.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6221

Confirmation

Confirm action

Continue?