关于 datadog-cli
Datadog CLI 是供 AI Agent 查询和排查 Datadog 日志与指标的命令行工具,涵盖日志搜索分析、指标查询、错误摘要和仪表板管理。
主要功能
- 01搜索并实时读取日志
- 02关联日志与追踪
- 03归类并比较日志模式
- 04查询时间序列指标
- 05管理仪表板及列表
适用场景
- 01根据近期日志排查服务错误
- 02比较不同时段的错误数量
- 03调试时检查指标
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ softaworks/ agent-toolkit --skill datadog-cli安装后在 Claude Code 中输入/datadog-cli确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
README.mdreferences/dashboards.mdlogs-commands.mdmetrics.mdquery-syntax.mdworkflows.md详细介绍
Datadog CLI
供 AI Agent 使用 Datadog 日志和指标进行调试与问题排查的 CLI 工具。
必读文档
使用任何命令前,你必须阅读相关参考文档:
设置
环境变量(必需)
export DD_API_KEY="your-api-key"
export DD_APP_KEY="your-app-key"
从此处获取密钥:https://app.datadoghq.com/organization-settings/api-keys
运行 CLI
npx @leoflores/datadog-cli <command>
对于非美国地区的 Datadog 站点,请使用 --site 标志:
npx @leoflores/datadog-cli logs search --query "*" --site datadoghq.eu
命令概览
| 命令 | 描述 |
|---|---|
logs search | 使用筛选条件搜索日志 |
logs tail | 实时流式传输日志 |
logs trace | 查找分布式跟踪对应的日志 |
logs context | 获取时间戳之前或之后的日志 |
logs patterns | 对相似的日志消息进行分组 |
logs compare | 比较不同时段的日志数量 |
logs multi | 并行运行多个查询 |
logs agg | 按 Facet 聚合日志 |
metrics query | 查询时间序列指标 |
errors | 按服务/类型快速汇总错误 |
services | 列出有日志活动的服务 |
dashboards | 管理仪表板(CRUD) |
dashboard-lists | 管理仪表板列表 |
快速示例
搜索错误
npx @leoflores/datadog-cli logs search --query "status:error" --from 1h --pretty
实时查看日志
npx @leoflores/datadog-cli logs tail --query "service:api status:error" --pretty
错误摘要
npx @leoflores/datadog-cli errors --from 1h --pretty
跟踪关联
npx @leoflores/datadog-cli logs trace --id "abc123def456" --pretty
查询指标
npx @leoflores/datadog-cli metrics query --query "avg:system.cpu.user{*}" --from 1h --pretty
比较时段
npx @leoflores/datadog-cli logs compare --query "status:error" --period 1h --pretty
全局标志
| 标志 | 描述 |
|---|---|
--pretty | 使用颜色输出易于阅读的内容 |
--output <file> | 将结果导出到 JSON 文件 |
--site <site> | Datadog 站点(例如,datadoghq.eu) |
时间格式
- 相对时间:
30m、1h、6h、24h、7d - ISO 8601:
2024-01-15T10:30:00Z
事件排查工作流
# 1. Quick error overview
npx @leoflores/datadog-cli errors --from 1h --pretty
# 2. Is this new? Compare to previous period
npx @leoflores/datadog-cli logs compare --query "status:error" --period 1h --pretty
# 3. Find error patterns
npx @leoflores/datadog-cli logs patterns --query "status:error" --from 1h --pretty
# 4. Narrow down by service
npx @leoflores/datadog-cli logs search --query "status:error service:api" --from 1h --pretty
# 5. Get context around a timestamp
npx @leoflores/datadog-cli logs context --timestamp "2024-01-15T10:30:00Z" --service api --pretty
# 6. Follow the distributed trace
npx @leoflores/datadog-cli logs trace --id "TRACE_ID" --pretty
更多调试工作流请参阅 workflows.md。
评论
支持 Markdown