← 返回 Skills 市场
peintune

loki-query

作者 GoodAtMe · GitHub ↗ · v1.0.1 · MIT-0
cross-platform ✓ 安全检测通过
169
总下载
1
收藏
0
当前安装
2
版本数
在 OpenClaw 中安装
/install loki-query
功能描述
Query Loki logs by traceid, keywords, pod, namespace, labels, or time range to debug and analyze Kubernetes application issues via API.
使用说明 (SKILL.md)

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:00Z to 2026-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
安全使用建议
This skill appears coherent for querying Loki. Before installing, consider: (1) ensure you trust the Loki endpoint you point it at (the script will send queries to whatever loki-url you provide); (2) if your Loki requires authentication, this script does not have built-in auth support — you would need to provide a secure proxy or extend the script rather than handing credentials to an unknown skill; (3) the examples use kubectl port-forward/exec which require cluster access — only run those commands in clusters you control; (4) as always, review the included script locally before running it in sensitive environments.
功能分析
Type: OpenClaw Skill Name: loki-query Version: 1.0.1 The skill bundle provides a legitimate utility for querying Grafana Loki logs. The Python script (scripts/query_loki.py) uses standard libraries to perform HTTP GET requests to a user-specified Loki endpoint and includes proper parameter encoding and error handling. No evidence of data exfiltration, malicious execution, or prompt injection was found.
能力评估
Purpose & Capability
Name/description (Loki queries by traceid/labels/time/pod/namespace) align with the included CLI script and examples. The skill only requires a Loki API URL and a LogQL query; nothing requested is disproportionate to log querying.
Instruction Scope
SKILL.md instructs running the bundled Python script or using kubectl port-forward/curl to reach Loki. The instructions do not ask the agent to read unrelated files or environment variables. Note: examples include kubectl exec/port-forward which legitimately require cluster access — expected for this use case.
Install Mechanism
No install spec (instruction-only) and a small included Python script. Nothing is downloaded or written to disk automatically by an installer, so installation risk is minimal.
Credentials
The skill declares no required environment variables or credentials. The script accepts a loki URL but does not attempt to read secrets from the environment. If the target Loki requires authentication, the skill currently has no explicit mechanism to provide auth headers (caller would need to run an authenticated proxy or modify the script).
Persistence & Privilege
always is false and the skill does not request persistent presence or modify other skills or system settings. Autonomous invocation is allowed by default but is not combined with other concerning privileges.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install loki-query
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /loki-query 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.1
- Enhanced documentation with two access modes: direct URL and Kubernetes port-forward. - Added example queries for error logs, trace IDs, and pod logs with JSON output. - Updated parameter list to include defaults, `--json` flag, and clarified required/optional fields. - Expanded common query patterns and example usages for clarity. - Improved output description, specifying formatted log lines are returned.
v1.0.0
Initial release – enables querying Loki logs for debugging and troubleshooting. - Query logs by trace ID, keywords, pod, namespace, labels, or time range. - Supports structured LogQL queries and common filter patterns. - Input parameters include traceid, keywords, start_time, end_time, pod, namespace, and labels. - Outputs logs as JSON with timestamp and log content.
元数据
Slug loki-query
版本 1.0.1
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 2
常见问题

loki-query 是什么?

Query Loki logs by traceid, keywords, pod, namespace, labels, or time range to debug and analyze Kubernetes application issues via API. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 169 次。

如何安装 loki-query?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install loki-query」即可一键安装,无需额外配置。

loki-query 是免费的吗?

是的,loki-query 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

loki-query 支持哪些平台?

loki-query 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 loki-query?

由 GoodAtMe(@peintune)开发并维护,当前版本 v1.0.1。

💬 留言讨论