oodle-metrics-query
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOodle Metrics Query — PromQL Instant and Range Queries
Oodle指标查询 — PromQL即时查询与范围查询
This skill teaches the agent to execute PromQL instant and range queries against Oodle metrics using the Prometheus-compatible query API.
本技能指导Agent使用兼容Prometheus的查询API对Oodle指标执行PromQL即时查询和范围查询。
Prerequisites
前提条件
bash
brew install oodle-ai/oodle/oodle
oodle configureConfirm the query endpoint works:
bash
oodle metrics query --query "up" -o json | jq '.status'bash
brew install oodle-ai/oodle/oodle
oodle configure确认查询端点可用:
bash
oodle metrics query --query "up" -o json | jq '.status'Command Execution Order
命令执行顺序
Before running any query command:
- Check whether the required metric name is already known.
- If not, run to discover metric names.
oodle metrics names --start -1h --end now - Run to discover available labels.
oodle metrics labels <name> --start -1h --end now - Build the PromQL expression using only confirmed metric names and labels.
- Do not run speculative queries — always confirm metric and label existence first.
运行任何查询命令之前:
- 检查是否已知晓所需的指标名称。
- 如果未知,运行 来发现指标名称。
oodle metrics names --start -1h --end now - 运行 来发现可用标签。
oodle metrics labels <name> --start -1h --end now - 仅使用已确认的指标名称和标签构建PromQL表达式。
- 不要运行推测性查询——始终先确认指标和标签是否存在。
Quick Reference
快速参考
| Task | Command |
|---|---|
| Instant PromQL query | |
| Instant query at specific time | |
| Range PromQL query | |
| Range query with partial response | |
| 任务 | 命令 |
|---|---|
| PromQL即时查询 | |
| 指定时间点的即时查询 | |
| PromQL范围查询 | |
| 带部分响应的范围查询 | |
Common Operations
常见操作
Instant query
即时查询
Evaluate a PromQL expression at a single point in time. Returns the current value by default, or the value at a specific timestamp.
bash
undefined在单个时间点计算PromQL表达式。默认返回当前值,或指定时间戳的值。
bash
undefinedCORRECT — instant query with JSON output for scripting
正确示例 — 适合脚本的JSON格式输出即时查询
oodle metrics query --query "sum(up)" -o json
oodle metrics query --query "sum(up)" -o json
CORRECT — instant query at a specific time
正确示例 — 指定时间点的即时查询
oodle metrics query --query "up{job="prometheus"}" --time 1700000000 -o json
oodle metrics query --query "up{job="prometheus"}" --time 1700000000 -o json
CORRECT — use relative time
正确示例 — 使用相对时间
oodle metrics query --query "up" --time -5m -o json
oodle metrics query --query "up" --time -5m -o json
WRONG — omitting --query flag
错误示例 — 省略--query参数
oodle metrics query -o json
undefinedoodle metrics query -o json
undefinedRange query
范围查询
Evaluate a PromQL expression over a time range. All four flags (, , , ) are required.
--query--start--end--stepbash
undefined在时间范围内计算PromQL表达式。四个参数(、、、)均为必填项。
--query--start--end--stepbash
undefinedCORRECT — range query over the last hour with 60-second resolution
正确示例 — 过去1小时内的范围查询,分辨率为60秒
oodle metrics query-range --query "rate(http_requests_total[5m])" --start -1h --end now --step 60s -o json
oodle metrics query-range --query "rate(http_requests_total[5m])" --start -1h --end now --step 60s -o json
CORRECT — range query with absolute timestamps
正确示例 — 使用绝对时间戳的范围查询
oodle metrics query-range --query "up" --start 1700000000 --end 1700003600 --step 60s -o json
oodle metrics query-range --query "up" --start 1700000000 --end 1700003600 --step 60s -o json
CORRECT — enable partial response for degraded-mode queries
正确示例 — 为降级模式查询启用部分响应
oodle metrics query-range --query "up" --start -1h --end now --step 60s --partial-response -o json
oodle metrics query-range --query "up" --start -1h --end now --step 60s --partial-response -o json
WRONG — missing --step flag
错误示例 — 缺少--step参数
oodle metrics query-range --query "up" --start -1h --end now -o json
oodle metrics query-range --query "up" --start -1h --end now -o json
WRONG — missing --start or --end
错误示例 — 缺少--start或--end参数
oodle metrics query-range --query "up" --step 60s -o json
undefinedoodle metrics query-range --query "up" --step 60s -o json
undefinedBest Practices
最佳实践
Use oodle metrics
to discover before querying
oodle metrics查询前使用oodle metrics
进行发现
oodle metricsAlways confirm metric names and labels exist before building a PromQL query. Querying a nonexistent metric returns empty results, not an error.
bash
undefined构建PromQL查询之前,务必确认指标名称和标签是否存在。查询不存在的指标会返回空结果,而非错误。
bash
undefinedCORRECT — discover first, then query
正确示例 — 先发现,再查询
oodle metrics names --start -1h --end now -o json | jq '.[] | select(startswith("http"))'
oodle metrics labels http_requests_total --start -1h --end now
oodle metrics query --query "sum(rate(http_requests_total[5m]))" -o json
oodle metrics names --start -1h --end now -o json | jq '.[] | select(startswith("http"))'
oodle metrics labels http_requests_total --start -1h --end now
oodle metrics query --query "sum(rate(http_requests_total[5m]))" -o json
WRONG — guessing metric names
错误示例 — 猜测指标名称
oodle metrics query --query "sum(rate(requests_total[5m]))" -o json
undefinedoodle metrics query --query "sum(rate(requests_total[5m]))" -o json
undefinedChoose the right step for range queries
为范围查询选择合适的step值
The step determines the resolution of the returned time series. Too small a step returns excessive data; too large a step misses detail.
bash
undefinedstep值决定返回时间序列的分辨率。step过小会返回过多数据;step过大则会丢失细节。
bash
undefinedCORRECT — 60s step for a 1-hour window (60 data points)
正确示例 — 1小时窗口使用60秒step(60个数据点)
oodle metrics query-range --query "up" --start -1h --end now --step 60s -o json
oodle metrics query-range --query "up" --start -1h --end now --step 60s -o json
CORRECT — 5m step for a 24-hour window (288 data points)
正确示例 — 24小时窗口使用5分钟step(288个数据点)
oodle metrics query-range --query "up" --start -1d --end now --step 5m -o json
oodle metrics query-range --query "up" --start -1d --end now --step 5m -o json
WRONG — 1s step for a 24-hour window (86400 data points — too many)
错误示例 — 24小时窗口使用1秒step(86400个数据点——数量过多)
oodle metrics query-range --query "up" --start -1d --end now --step 1s -o json
undefinedoodle metrics query-range --query "up" --start -1d --end now --step 1s -o json
undefinedFailure Handling
故障处理
| Error | Cause | Fix |
|---|---|---|
| 401 Unauthorized | Invalid or missing API key | Run |
| 400 Bad Request | Invalid PromQL expression | Check syntax at https://prometheus.io/docs/prometheus/latest/querying/basics/ |
| Empty result (not an error) | Metric does not exist or no data in time range | Run |
| connection refused | Wrong | Check |
| 429 Too Many Requests | Rate limited | Add |
| Missing required flag for range query | Add |
| Missing required flag | Add |
| 错误 | 原因 | 解决方法 |
|---|---|---|
| 401 Unauthorized | API密钥无效或缺失 | 运行 |
| 400 Bad Request | PromQL表达式无效 | 访问https://prometheus.io/docs/prometheus/latest/querying/basics/检查语法 |
| 空结果(非错误) | 指标不存在或时间范围内无数据 | 运行 |
| connection refused | | 检查 |
| 429 Too Many Requests | 触发速率限制 | 添加 |
| 范围查询缺少必填参数 | 添加 |
| 缺少必填参数 | 添加 |