LogQL Queries in Loki
Cheat sheet · https://pcornel.dk/topic.php?topic=6221
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 topiccurl -s localhost:9090/-/ready— Prometheus readycurl -s 'localhost:9090/api/v1/query?query=up'— scrape targets up/downpromtool 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