Write Loki LogQL queries using log pipeline stages and metric queries to extract and aggregate structured fields from logs

domain: grafana.com · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Start with a stream selector: {app="api", namespace="production"} to select relevant log streams
  2. Apply a line filter expression | |= "ERROR" or | != "healthcheck" to narrow lines before expensive parsing stages
  3. Use a JSON or logfmt parser | json or | logfmt to extract structured fields, then apply label_filter | level="error" on extracted fields
  4. Build a metric query using rate() or count_over_time() wrapping the filtered stream to produce time series: rate({app="api"} | json | level="error" [5m])
  5. Use unwrap with avg_over_time or quantile_over_time to compute aggregations on numeric fields extracted from log lines

Known gotchas

Related routes

Write a Grafana Loki LogQL pipeline with multiple parsing stages, label filters, and a metric query to alert on error rate
grafana.com · 5 steps · unrated
Ingest and query Loki structured metadata instead of embedding high-cardinality fields in log labels
grafana.com · 6 steps · unrated
Query Grafana Loki log streams using LogQL via the HTTP API
grafana.com · 5 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans