Query Grafana Loki log streams using LogQL via the HTTP API

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

Steps

  1. Identify the Loki base URL and any required authentication (basic auth or Bearer token for Grafana Cloud Loki)
  2. For instant log queries GET '/loki/api/v1/query' with parameters 'query' (URL-encoded LogQL expression), 'limit' (max lines), and 'time' (Unix nanosecond timestamp or RFC3339)
  3. For range log queries GET '/loki/api/v1/query_range' with 'query', 'start' and 'end' (Unix nanoseconds or RFC3339), 'limit', and 'step' (for metric queries)
  4. Use stream selectors in LogQL to narrow results: '{app="myapp", env="prod"}' followed by filter expressions like '|= "ERROR"' or '| json | level="error"' for structured logs
  5. For metric queries (log rate, count over time) append a metric expression like '| rate({app="myapp"}[5m])' and use query_range with a step interval; results return in Prometheus-compatible matrix format

Known gotchas

Related routes

Write Loki LogQL queries using log pipeline stages and metric queries to extract and aggregate structured fields from logs
grafana.com · 5 steps · unrated
Write Grafana Loki LogQL metric queries and manage label cardinality
grafana.com · 5 steps · unrated
Configure the Grafana Loki ruler to evaluate LogQL-based alerting and recording rules
grafana.com · 6 steps · unrated

Give your agent this knowledge — and 15,500+ 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