datadog-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDatadog CLI
Datadog CLI
A CLI tool for AI agents to debug and triage using Datadog logs and metrics.
一款供AI Agent使用的CLI工具,可借助Datadog日志和指标进行调试与问题分类。
Required Reading
必读内容
You MUST read the relevant reference docs before using any command:
- Log Commands
- Metrics
- Query Syntax
- Workflows
- Dashboards
在使用任何命令前,你必须阅读相关参考文档:
- 日志命令
- 指标
- 查询语法
- 工作流
- 仪表板
Setup
设置
Environment Variables (Required)
环境变量(必填)
bash
export DD_API_KEY="your-api-key"
export DD_APP_KEY="your-app-key"Get keys from: https://app.datadoghq.com/organization-settings/api-keys
bash
export DD_API_KEY="your-api-key"
export DD_APP_KEY="your-app-key"Running the CLI
运行CLI
bash
npx @leoflores/datadog-cli <command>For non-US Datadog sites, use flag:
--sitebash
npx @leoflores/datadog-cli logs search --query "*" --site datadoghq.eubash
npx @leoflores/datadog-cli <command>对于非美国区的Datadog站点,使用参数:
--sitebash
npx @leoflores/datadog-cli logs search --query "*" --site datadoghq.euCommands Overview
命令概览
| Command | Description |
|---|---|
| Search logs with filters |
| Stream logs in real-time |
| Find logs for a distributed trace |
| Get logs before/after a timestamp |
| Group similar log messages |
| Compare log counts between periods |
| Run multiple queries in parallel |
| Aggregate logs by facet |
| Query timeseries metrics |
| Quick error summary by service/type |
| List services with log activity |
| Manage dashboards (CRUD) |
| Manage dashboard lists |
| 命令 | 描述 |
|---|---|
| 使用过滤器搜索日志 |
| 实时流式查看日志 |
| 查找分布式追踪对应的日志 |
| 获取指定时间戳前后的日志 |
| 分组相似的日志消息 |
| 对比不同时间段的日志数量 |
| 并行运行多个查询 |
| 按维度聚合日志 |
| 查询时间序列指标 |
| 按服务/类型快速汇总错误 |
| 列出有日志活动的服务 |
| 管理仪表板(增删改查) |
| 管理仪表板列表 |
Quick Examples
快速示例
Search Errors
搜索错误
bash
npx @leoflores/datadog-cli logs search --query "status:error" --from 1h --prettybash
npx @leoflores/datadog-cli logs search --query "status:error" --from 1h --prettyTail Logs (Real-time)
实时查看日志
bash
npx @leoflores/datadog-cli logs tail --query "service:api status:error" --prettybash
npx @leoflores/datadog-cli logs tail --query "service:api status:error" --prettyError Summary
错误汇总
bash
npx @leoflores/datadog-cli errors --from 1h --prettybash
npx @leoflores/datadog-cli errors --from 1h --prettyTrace Correlation
追踪关联
bash
npx @leoflores/datadog-cli logs trace --id "abc123def456" --prettybash
npx @leoflores/datadog-cli logs trace --id "abc123def456" --prettyQuery Metrics
查询指标
bash
npx @leoflores/datadog-cli metrics query --query "avg:system.cpu.user{*}" --from 1h --prettybash
npx @leoflores/datadog-cli metrics query --query "avg:system.cpu.user{*}" --from 1h --prettyCompare Periods
对比时间段
bash
npx @leoflores/datadog-cli logs compare --query "status:error" --period 1h --prettybash
npx @leoflores/datadog-cli logs compare --query "status:error" --period 1h --prettyGlobal Flags
全局参数
| Flag | Description |
|---|---|
| Human-readable output with colors |
| Export results to JSON file |
| Datadog site (e.g., |
| 参数 | 描述 |
|---|---|
| 带颜色的人类可读格式输出 |
| 将结果导出为JSON文件 |
| Datadog站点(例如: |
Time Formats
时间格式
- Relative: ,
30m,1h,6h,24h7d - ISO 8601:
2024-01-15T10:30:00Z
- 相对时间:,
30m,1h,6h,24h7d - ISO 8601格式:
2024-01-15T10:30:00Z
Incident Triage Workflow
事件分类工作流
bash
undefinedbash
undefined1. Quick error overview
1. 快速查看错误概览
npx @leoflores/datadog-cli errors --from 1h --pretty
npx @leoflores/datadog-cli errors --from 1h --pretty
2. Is this new? Compare to previous period
2. 这是新问题吗?与之前时间段对比
npx @leoflores/datadog-cli logs compare --query "status:error" --period 1h --pretty
npx @leoflores/datadog-cli logs compare --query "status:error" --period 1h --pretty
3. Find error patterns
3. 查找错误模式
npx @leoflores/datadog-cli logs patterns --query "status:error" --from 1h --pretty
npx @leoflores/datadog-cli logs patterns --query "status:error" --from 1h --pretty
4. Narrow down by service
4. 按服务缩小范围
npx @leoflores/datadog-cli logs search --query "status:error service:api" --from 1h --pretty
npx @leoflores/datadog-cli logs search --query "status:error service:api" --from 1h --pretty
5. Get context around a timestamp
5. 获取指定时间戳前后的上下文日志
npx @leoflores/datadog-cli logs context --timestamp "2024-01-15T10:30:00Z" --service api --pretty
npx @leoflores/datadog-cli logs context --timestamp "2024-01-15T10:30:00Z" --service api --pretty
6. Follow the distributed trace
6. 追踪分布式链路
npx @leoflores/datadog-cli logs trace --id "TRACE_ID" --pretty
See [workflows.md](references/workflows.md) for more debugging workflows.npx @leoflores/datadog-cli logs trace --id "TRACE_ID" --pretty
更多调试工作流请查看[workflows.md](references/workflows.md)。