/install loki-query
Loki Log Query
Query logs from Grafana Loki using the bundled script.
Two Access Modes
1. Direct URL Access (Recommended)
Use when Loki is accessible via network (cloud service, remote server, etc.):
# Using remote Loki URL
python scripts/query_loki.py \
--loki-url "https://loki.example.com:3100" \
--query "{namespace=\"default\"}" \
--start "now-1h" \
--limit 50
2. Kubernetes Port-Forward
Use when Loki is only accessible via kubectl:
# Terminal 1: Port-forward Loki
kubectl port-forward -n prometheus svc/loki 3100:3100
# Terminal 2: Query logs
python scripts/query_loki.py \
--loki-url "http://localhost:3100" \
--query "{namespace=\"default\"}"
Or use inline port-forward with kubectl exec:
kubectl exec -n prometheus \x3Cloki-pod> -- curl -s "http://localhost:3100/loki/api/v1/query_range?query={namespace=\"default\"}&limit=50"
Query Script
Use scripts/query_loki.py to query logs:
python scripts/query_loki.py \
--loki-url "http://localhost:3100" \
--query '{namespace="default"}' \
--start "now-1h" \
--end "now" \
--limit 100
Default: If --loki-url is not specified, uses http://localhost:3100.
Common Query Patterns
By Namespace
{namespace="\x3Cnamespace>"}
By Pod
{namespace="\x3Cnamespace>", pod="\x3Cpod-name>"}
By Labels
{namespace="\x3Cns>", app="\x3Capp-label>"}
Search Keywords
{namespace="\x3Cns>"} |= "ERROR"
{namespace="\x3Cns>"} |= "traceid=\x3Ctrace-id>"
{namespace="\x3Cns>"} |= "Exception"
Time Range
- Last 1 hour:
now-1h - Last 30 minutes:
now-30m - Specific range:
2026-03-27T10:00:00Zto2026-03-27T11:00:00Z
Parameters
loki-url: Loki API endpoint (default: http://localhost:3100)query: LogQL query string (required)start: Start time (ISO 8601 or relative like now-1h, default: now-1h)end: End time (ISO 8601 or relative like now, default: now)limit: Max results (default: 100)direction: "forward" or "backward" (default: backward)--json: Output raw JSON instead of formatted text
Output
Returns formatted log lines. Each entry shows timestamp and log content.
Examples
Query error logs from last hour
python scripts/query_loki.py --query '{namespace="production"} |= "ERROR"'
Query specific trace ID
python scripts/query_loki.py --query '{namespace="default"} |= "traceid=abc123"'
Query pod logs with JSON output
python scripts/query_loki.py --query '{namespace="default",pod="my-app-0"}' --json
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install loki-query - After installation, invoke the skill by name or use
/loki-query - Provide required inputs per the skill's parameter spec and get structured output
What is loki-query?
Query Loki logs by traceid, keywords, pod, namespace, labels, or time range to debug and analyze Kubernetes application issues via API. It is an AI Agent Skill for Claude Code / OpenClaw, with 169 downloads so far.
How do I install loki-query?
Run "/install loki-query" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is loki-query free?
Yes, loki-query is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does loki-query support?
loki-query is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created loki-query?
It is built and maintained by GoodAtMe (@peintune); the current version is v1.0.1.