agentleFS
abdullahkhawerabdullahkhawer/devops-skills/skills/grafana-loki-cli/SKILL.md

grafana-loki-cli

Skill8 starsChanged 6 months agoApache-2.0View on GitHub

Query Grafana Loki logs using the Loki HTTP API via curl or logcli. Use for LogQL queries, label exploration, and tailing log streams.

  • Installs packages

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 4 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use the instance and rules below when constructing all Loki API/logcli commands.

    line 8
  2. Distinctive:

    Update the table below with your Loki instance URLs and token file paths:

    line 12
  3. Distinctive:

    If the target instance is unclear, ask the user before running any command.

    line 19
  4. Distinctive:

    NEVER target any Loki instance not listed in the instance table above.

    line 71
  5. Distinctive:

    NEVER print, display, log, or store the contents of any token file.

    line 72
  6. Very specific:

    Always read the token inline with $(cat <TOKEN_FILE>) — never hardcode a token value in a command.

    line 73
  7. Very specific:

    Always pass -s (silent) to curl and pipe through jq for readable output.

    line 74
  8. Very specific:

    Always set a bounded time range (start/end or --since) and a reasonable limit — an unbounded LogQL query over a busy stream can be slow and …

    line 76
  9. Very specific:

    If a label name or stream selector is unfamiliar, use /loki/api/v1/labels and label/<name>/values to explore before querying.

    line 77

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Grafana Loki CLI Skill

Use the instance and rules below when constructing all Loki API/logcli commands.

Instances

Update the table below with your Loki instance URLs and token file paths:

EnvironmentBase URLToken File
Productionhttps://<your-loki-prod-url>~/.loki/prod.token
Staginghttps://<your-loki-staging-url>~/.loki/staging.token

If the target instance is unclear, ask the user before running any command.

Prerequisites (one-time setup by user)

Obtain a Loki API token (or basic-auth credentials, depending on setup) for each instance and save it to the corresponding token file. Never print or display token values. Do not perform these steps yourself.

brew install logcli
mkdir -p ~/.loki && echo "<your-api-token>" > <TOKEN_FILE> && chmod 600 <TOKEN_FILE>

Command Format

Via curl:

curl -s -H "Authorization: Bearer $(cat <TOKEN_FILE>)" \
  "<BASE_URL>/loki/api/v1/<endpoint>" | jq .

Via logcli:

logcli --addr="<BASE_URL>" --bearer-token="$(cat <TOKEN_FILE>)" <command>

Available API Endpoints / Commands

Read-only (safe, no confirmation needed)

Endpoint / logcli commandDescription
/loki/api/v1/query / logcli query '<LogQL>'Run an instant LogQL query
/loki/api/v1/query_range / logcli query '<LogQL>' --from=<t> --to=<t>Run a LogQL range query
/loki/api/v1/labels / logcli labelsList all label names
/loki/api/v1/label/<name>/values / logcli labels <name>List values for a label
/loki/api/v1/series?match[]=<selector> / logcli series '<selector>'Find streams matching a selector
/readyCheck readiness/health
logcli query '<LogQL>' --tailTail a live log stream (read-only)

Example Queries

# Instant query — errors in the last 5 minutes for a job
curl -s -H "Authorization: Bearer $(cat <TOKEN_FILE>)" \
  "<BASE_URL>/loki/api/v1/query_range?query={job=\"<job-name>\"}|=\"error\"&start=$(( $(date -u +%s) - 300 ))000000000&end=$(date -u +%s)000000000&limit=100" | jq .

# logcli equivalent
logcli --addr="<BASE_URL>" --bearer-token="$(cat <TOKEN_FILE>)" \
  query '{job="<job-name>"} |= "error"' --since=5m --limit=100

Rules

  • NEVER target any Loki instance not listed in the instance table above. If a URL references a different host, stop and ask the user to confirm.
  • NEVER print, display, log, or store the contents of any token file.
  • Always read the token inline with $(cat <TOKEN_FILE>) — never hardcode a token value in a command.
  • Always pass -s (silent) to curl and pipe through jq for readable output.
  • Loki's public API is read-only for queries (no delete/mutate endpoints exposed) — no destructive operations to guard against here, other than avoiding excessive queries.
  • Always set a bounded time range (start/end or --since) and a reasonable limit — an unbounded LogQL query over a busy stream can be slow and return excessive data.
  • If a label name or stream selector is unfamiliar, use /loki/api/v1/labels and label/<name>/values to explore before querying.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.