oodle-log-metrics
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOodle Log Metrics — Rules and Cardinality
Oodle日志指标——规则与基数
This skill teaches the agent to convert log streams into metrics safely: validate the filter, narrow the , and avoid creating high-cardinality time series.
groupBy本技能指导Agent安全地将日志流转换为指标:验证过滤器、精简标签,避免创建高基数时间序列。
groupByPrerequisites
前置条件
bash
brew install oodle-ai/oodle/oodle
oodle configureConfirm the log-metrics endpoint works:
bash
oodle log-metrics list -o json | jq 'length'bash
brew install oodle-ai/oodle/oodle
oodle configure确认日志指标端点正常工作:
bash
oodle log-metrics list -o json | jq 'length'Command Execution Order
命令执行顺序
Before running any oodle command:
- Check whether the rule's filter and are already in context.
groupBy - If not, run a sample log query (e.g. or the log explorer) to verify the filter actually matches logs.
oodle traces list ... - Estimate cardinality: count × distinct values per label.
groupBy - Run only after the filter is validated.
oodle log-metrics create -f rule.json - Do not run without first running
updateto capture the existing rule.get
运行任何oodle命令前:
- 检查规则的过滤器和是否已在上下文之中。
groupBy - 如果没有,运行示例日志查询(如或日志探索器)验证过滤器是否确实匹配日志。
oodle traces list ... - 估算基数:标签数量 × 每个标签的不同值数量。
groupBy - 仅在过滤器验证通过后,运行。
oodle log-metrics create -f rule.json - 未先运行获取现有规则前,不要执行
get操作。update
Quick Reference
快速参考
| Task | Command |
|---|---|
| List rules | |
| Get rule | |
| Create rule | |
| Update rule | |
| Delete rule | |
| 任务 | 命令 |
|---|---|
| 列出规则 | |
| 获取规则 | |
| 创建规则 | |
| 更新规则 | |
| 删除规则 | |
Common Operations
常见操作
Rule schema
规则 schema
json
{
"name": "http_errors_from_logs",
"filter": "level=error AND service=api",
"groupBy": ["service", "env"],
"metricName": "oodle.log.http_errors"
}Field meaning:
| Field | Meaning |
|---|---|
| Human identifier for the rule |
| Boolean expression over log fields ( |
| Labels promoted from log fields onto the emitted metric |
| The Prometheus-style metric name to emit |
json
{
"name": "http_errors_from_logs",
"filter": "level=error AND service=api",
"groupBy": ["service", "env"],
"metricName": "oodle.log.http_errors"
}字段含义:
| 字段 | 含义 |
|---|---|
| 规则的人工识别名称 |
| 基于日志字段的布尔表达式(支持 |
| 从日志字段提取并附加到生成指标上的标签 |
| 要生成的Prometheus风格指标名称 |
Creating a rule
创建规则
bash
undefinedbash
undefined✅ CORRECT — validate filter first, then create
✅ 正确做法 — 先验证过滤器,再创建
(preview with the log explorer or oodle traces list
if traces and logs share the same backend)
oodle traces list—
oodle log-metrics create -f rule.json
#(如果追踪和日志共享同一后端,可通过日志探索器或预览)
oodle log-metrics create -f rule.json
oodle traces list❌ WRONG — creating with an untested filter; the resulting metric is silently empty
❌ 错误做法 — 使用未测试的过滤器创建规则,生成的指标会静默无数据
oodle log-metrics create -f <(echo '{"name":"x","filter":"levl=eror","groupBy":[],"metricName":"x"}')
undefinedoodle log-metrics create -f <(echo '{"name":"x","filter":"levl=eror","groupBy":[],"metricName":"x"}')
undefinedUpdating a rule
更新规则
bash
undefinedbash
undefined✅ CORRECT — get → edit → update
✅ 正确做法 — 获取→编辑→更新
oodle log-metrics get lm_123 -o json > rule.json
jq '.groupBy = ["service","env"]' rule.json > rule.new.json
oodle log-metrics update lm_123 -f rule.new.json
oodle log-metrics get lm_123 -o json > rule.json
jq '.groupBy = ["service","env"]' rule.json > rule.new.json
oodle log-metrics update lm_123 -f rule.new.json
❌ WRONG — partial payload removes existing fields
❌ 错误做法 — 部分请求体会删除现有字段
oodle log-metrics update lm_123 -f <(echo '{"groupBy":["service"]}')
undefinedoodle log-metrics update lm_123 -f <(echo '{"groupBy":["service"]}')
undefinedDeleting a rule
删除规则
bash
undefinedbash
undefined✅ CORRECT — verify and delete
✅ 正确做法 — 验证后删除
oodle log-metrics get lm_123 -o json > /dev/null
oodle log-metrics delete lm_123 --force
oodle log-metrics get lm_123 -o json > /dev/null
oodle log-metrics delete lm_123 --force
❌ WRONG — speculative delete by name match
❌ 错误做法 — 通过名称匹配推测性删除
oodle log-metrics delete "$(oodle log-metrics list | grep errors | awk '{print $1}')" --force
undefinedoodle log-metrics delete "$(oodle log-metrics list | grep errors | awk '{print $1}')" --force
undefinedBest Practices
最佳实践
Validate the filter
against real log volume before creating the rule
filter创建规则前,针对真实日志量验证filter
filterA typo in the filter () creates a rule that silently emits zero data points.
levl=erorbash
undefined过滤器中的拼写错误(如)会创建一个静默生成零数据点的规则。
levl=erorbash
undefined✅ CORRECT — preview matching log volume in the log explorer first;
✅ 正确做法 — 先在日志探索器中预览匹配的日志量;
only then run oodle log-metrics create
oodle log-metrics create之后再运行oodle log-metrics create
oodle log-metrics create(or temporarily create a synthetic monitor that hits the matching logs and confirm count > 0)
—
❌ WRONG — create the rule, then notice the dashboard panel is empty next week
—
oodle log-metrics create -f rule.json
undefined#(或临时创建一个命中匹配日志的合成监控,确认计数>0)
Keep groupBy
to 2–3 low-cardinality labels
groupBy❌ 错误做法 — 创建规则,之后才发现下周仪表盘面板为空
Each label multiplies the time-series count. Avoid , , , (with IDs).
request_iduser_idtrace_idpathbash
undefinedoodle log-metrics create -f rule.json
undefined✅ CORRECT — bounded labels
将groupBy
限制为2-3个低基数标签
groupBy"groupBy": ["service", "env"]
每个标签都会增加时间序列的数量。避免使用、、、(含ID的路径)。
request_iduser_idtrace_idpathbash
undefined❌ WRONG — user_id
blows up cardinality (one series per user)
user_id✅ 正确做法 — 有限基数的标签
"groupBy": ["service", "env", "user_id"]
undefined"groupBy": ["service", "env"]
Always get
before update
to preserve fields
getupdate❌ 错误做法 — user_id
会大幅提升基数(每个用户对应一个序列)
user_idupdatebash
undefined"groupBy": ["service", "env", "user_id"]
undefined✅ CORRECT
执行update
前务必先get
以保留字段
updategetoodle log-metrics get lm_123 -o json > rule.json
jq '.filter = "level=error AND service=api AND status=5xx"' rule.json > rule.new.json
oodle log-metrics update lm_123 -f rule.new.json
updatebash
undefined❌ WRONG — clobbers groupBy and metricName
✅ 正确做法
oodle log-metrics update lm_123 -f <(echo '{"filter":"level=error"}')
undefinedoodle log-metrics get lm_123 -o json > rule.json
jq '.filter = "level=error AND service=api AND status=5xx"' rule.json > rule.new.json
oodle log-metrics update lm_123 -f rule.new.json
Use a stable, namespaced metricName
metricName❌ 错误做法 — 会覆盖groupBy和metricName
oodle.log.<domain>.<measurement>bash
undefinedoodle log-metrics update lm_123 -f <(echo '{"filter":"level=error"}')
undefined✅ CORRECT
使用稳定的命名空间式metricName
metricName"metricName": "oodle.log.http_errors"
oodle.log.<领域>.<度量>bash
undefined❌ WRONG — generic name collides with other rules
✅ 正确做法
"metricName": "errors"
undefined"metricName": "oodle.log.http_errors"
Failure Handling
❌ 错误做法 — 通用名称会与其他规则冲突
| Error | Cause | Fix |
|---|---|---|
| 401 Unauthorized | Invalid or missing API key | Run |
| 404 Not Found | Log-metric rule ID does not exist | Verify with |
| connection refused | Wrong | Check |
| Filter has a syntax error | Use |
| Metric exists but has no data points | Filter doesn't match any logs | Re-test the filter in the log explorer; check label names match the log schema |
| Cardinality alarm in the UI | | Edit the rule to drop that field; old series age out at the regular retention |
| 429 Too Many Requests | Bulk rule creation | Add |
"metricName": "errors"
undefinedReferences
故障处理
| 错误 | 原因 | 解决方法 |
|---|---|---|
| 401 Unauthorized | API密钥无效或缺失 | 运行 |
| 404 Not Found | 日志指标规则ID不存在 | 通过 |
| connection refused | | 检查 |
| 过滤器存在语法错误 | 使用 |
| 指标存在但无数据点 | 过滤器未匹配任何日志 | 在日志探索器中重新测试过滤器;检查标签名称与日志schema是否匹配 |
| UI中出现基数告警 | | 编辑规则移除该字段;旧序列会按常规保留周期自动过期 |
| 429 Too Many Requests | 批量创建规则 | 添加 |
—