返回顶部
l

loki-query

Query Loki logs via API for debugging and troubleshooting. Use when user needs to: (1) Query logs by traceid or keywords, (2) Filter logs by pod name, namespace, labels, or time range, (3) Debug application issues using structured log queries, (4) Analyze logs from Kubernetes pods. Accepts parameters like traceid, keywords, start_time, end_time, pod, namespace, labels, loki_url.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.1
安全检测
已通过
99
下载量
1
收藏
概述
安装方式
版本历史

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.): ```bash # 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: ```bash # 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: ```bash kubectl exec -n prometheus <loki-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: ```bash 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="<namespace>"} ``` ### By Pod ``` {namespace="<namespace>", pod="<pod-name>"} ``` ### By Labels ``` {namespace="<ns>", app="<app-label>"} ``` ### Search Keywords ``` {namespace="<ns>"} |= "ERROR" {namespace="<ns>"} |= "traceid=<trace-id>" {namespace="<ns>"} |= "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 ```bash python scripts/query_loki.py --query '{namespace="production"} |= "ERROR"' ``` ### Query specific trace ID ```bash python scripts/query_loki.py --query '{namespace="default"} |= "traceid=abc123"' ``` ### Query pod logs with JSON output ```bash python scripts/query_loki.py --query '{namespace="default",pod="my-app-0"}' --json ```

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 loki-query-1775935474 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 loki-query-1775935474 技能

通过命令行安装

skillhub install loki-query-1775935474

下载 Zip 包

⬇ 下载 loki-query v1.0.1

文件大小: 3.61 KB | 发布时间: 2026-4-12 10:28

v1.0.1 最新 2026-4-12 10:28
- 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.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部