---
name: "loki-logcli-logql-queries"
description: "Query, filter, and extract numerical metrics from petabytes of application logs using LogQL."
metadata:
  author: "Grafana Labs"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "write logql query loki"
  - "extract metrics from logs loki"
  - "query loki with logcli"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Grafana Loki LogQL Queries & High-Cardinality Parsing

Queries logs with Grafana Loki and LogCLI: writing LogQL stream selectors ({app='api'}), line filters (|= 'error'), parser stages (json, logfmt, pattern), metric queries (rate, count_over_time), and quantile over time.

## When to Invoke
Invoke this skill whenever you need to:
- write logql query loki
- extract metrics from logs loki
- query loki with logcli

## Execution SOP & Rules
1. Write stream selector matching low-cardinality labels: {environment='prod', app='payment'}.
2. Pipe to parser stage: | json | status >= 500 or | logfmt | duration > 2s.
3. Compute metrics from logs: sum by(status) (rate({app='payment'} | json [5m])).
4. Query via command-line: logcli query --timezone=UTC '{app="payment"} |= "error"' --limit=50.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
