loki-log-search

Search and scan Grafana Loki logs for errors and anomalies via gcx api passthrough.

Updated Apr 28, 2026
One-click install
npx skills add https://github.com/byron1st/personal-harness --skill loki-log-search-byron1st
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: loki-log-search
Source: https://github.com/byron1st/personal-harness/tree/main/skills/loki-log-search
Command: npx skills add https://github.com/byron1st/personal-harness --skill loki-log-search-byron1st

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Investigating production errors on a Grafana + Loki stack usually means clicking through the Grafana UI or fighting typed CLI commands that silently return empty results on self-hosted instances. This Skill queries Loki directly through the classic REST API via gcx api passthrough, so you can find where errors cluster and drill into raw log lines without a browser. ## Core Features & Use Cases - Datasource discovery: Resolve the Loki datasource UID through the classic /api/datasources endpoint, avoiding the app-platform API that is often disabled by feature flags on self-hosted Grafana. - Scan-then-drill workflow: Aggregate with count_over_time over a wide time range to locate error spikes, then fetch raw log lines only for the narrow spike window, keeping context usage small. - Correct query encoding: Percent-encode the LogQL value exactly once with jq @uri and embed it in the proxy path, with verbose-mode verification to catch double-encoding. - Use Case: A service started throwing errors overnight. Scan the last 3 days with an hourly count_over_time query to find the spike at 03:00, then drill into that 30-minute window to extract the top error signatures and affected labels. ## Quick Start Ask the agent to scan the last three days of Loki logs for the service "foo" and summarize where errors cluster, then show the raw error lines from the busiest hour.

Frequently Asked Questions about loki-log-search

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I query Loki logs from the command line without the Grafana UI?▼

Use gcx api passthrough to the classic Loki proxy endpoint at /api/datasources/proxy/uid/<uid>/loki/api/v1/query_range. Resolve the datasource UID from /api/datasources first, then send your LogQL query percent-encoded in the query parameter.

How do I find when errors spiked in Loki logs?▼

Run a count_over_time metric query with query_range and a step like 1h over a wide window, then read .data.result[].values to find timestamps with elevated counts. Fetch raw log lines only for that narrow spike window instead of pulling days of logs.

Why do gcx datasources query commands return empty results on self-hosted Grafana?▼

The typed commands route through the newer app-platform API (datasource.grafana.app), which is frequently disabled by feature flag on self-hosted instances. The classic /api/datasources and proxy endpoints work with the context's token and return the actual data.

Why does my Loki query fail with encoding errors through gcx api?▼

gcx api forwards the query string verbatim without re-encoding, so the LogQL value must be percent-encoded exactly once using jq -rn --arg q "$LOGQL" '$q|@uri'. Verify with gcx -v api: a { should appear as %7B; %257B means it was double-encoded.

What should I check when Loki queries return empty results everywhere?▼

Empty results across all queries usually indicate an org mismatch or missing RBAC, not an encoding problem. A service-account token is bound to the org it was created in, so confirm the org with gcx api /api/org and verify the account has datasources:read permission.