datadog-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesedatadog CLI
datadog CLI
A command-line tool for interacting with the Datadog API. Built with Go, cobra, and .
datadog-api-client-go/v2一款用于与Datadog API交互的命令行工具,基于Go、cobra和构建。
datadog-api-client-go/v2Prerequisites
前置条件
Set environment variables before use:
bash
export DD_API_KEY="your-api-key"
export DD_APP_KEY="your-app-key"使用前请设置环境变量:
bash
export DD_API_KEY="your-api-key"
export DD_APP_KEY="your-app-key"Global Flags
全局标志
| Flag | Description |
|---|---|
| Output in JSON format (default: table) |
| Datadog site (default: |
| 标志 | 描述 |
|---|---|
| 以JSON格式输出(默认:表格) |
| Datadog站点(默认: |
Command Map
命令映射
datadog
├── monitor Manage monitors (alerts)
│ ├── list List monitors with filters
│ ├── get Get monitor details by ID
│ ├── search Search monitors by query
│ ├── create Create a monitor (standard or log-based formula)
│ ├── update Update monitor properties and thresholds
│ └── delete Delete a monitor
│
├── metric Query metric data
│ └── query Query scalar metric values
│
├── event Query events
│ └── list List events with time range and filters
│
├── log Query logs
│ └── search Search logs by query
│
├── service Query APM services
│ └── list List active services by environment
│
├── error Error Tracking (aliases: error, errors)
│ ├── search Search error issues
│ └── get Get error issue details
│
└── pipeline Manage log processing pipelines
├── list List all pipelines
├── get Get pipeline details with processors
├── create Create a new pipeline
├── delete Delete a pipeline
├── add-category Add a Category Processor
└── add-remapper Add an Attribute Remapperdatadog
├── monitor 管理监控器(告警)
│ ├── list 按过滤器列出监控器
│ ├── get 通过ID获取监控器详情
│ ├── search 按查询语句搜索监控器
│ ├── create 创建监控器(标准或基于日志的公式型)
│ ├── update 更新监控器属性和阈值
│ └── delete 删除监控器
│
├── metric 查询指标数据
│ └── query 查询标量指标值
│
├── event 查询事件
│ └── list 按时间范围和过滤器列出事件
│
├── log 查询日志
│ └── search 按查询语句搜索日志
│
├── service 查询APM服务
│ └── list 按环境列出活跃服务
│
├── error 错误追踪(别名:error、errors)
│ ├── search 搜索错误问题
│ └── get 获取错误问题详情
│
└── pipeline 管理日志处理管道
├── list 列出所有管道
├── get 获取包含处理器的管道详情
├── create 创建新管道
├── delete 删除管道
├── add-category 添加分类处理器
└── add-remapper 添加属性重映射器Quick Reference
快速参考
For detailed usage of each command group, read the corresponding reference file:
| Task | Command | Reference |
|---|---|---|
| List/search/create/update/delete monitors | | |
| Query metric values to validate thresholds | | |
| Search events and alert history | | |
| Search logs for errors or patterns | | |
| List active APM services | | |
| Search/view Error Tracking issues | | |
| Manage log pipelines and processors | | |
如需了解每个命令组的详细用法,请阅读对应的参考文档:
| 任务 | 命令 | 参考文档 |
|---|---|---|
| 列出/搜索/创建/更新/删除监控器 | | |
| 查询指标值以验证阈值 | | |
| 搜索事件和告警历史 | | |
| 搜索日志中的错误或模式 | | |
| 列出活跃APM服务 | | |
| 搜索/查看错误追踪问题 | | |
| 管理日志管道和处理器 | | |
Common Workflows
常见工作流
Investigate a service's health
排查服务健康状况
bash
datadog service list --env prod # confirm service is active
datadog log search "service:myapp status:error" --from 1h
datadog error search "service:myapp" --track trace --from 24h
datadog metric query "avg:trace.http.request.errors{service:myapp}.as_count()" --from 1hbash
datadog service list --env prod # 确认服务处于活跃状态
datadog log search "service:myapp status:error" --from 1h
datadog error search "service:myapp" --track trace --from 24h
datadog metric query "avg:trace.http.request.errors{service:myapp}.as_count()" --from 1hAudit and fix monitors
审计并修复监控器
bash
datadog monitor list --json # export all monitors
datadog monitor get <id> # inspect a specific one
datadog metric query "<monitor-query>" --from 1h # validate threshold against actual values
datadog monitor update <id> --threshold-critical 100 --threshold-warning 80 --renotify 30bash
datadog monitor list --json # 导出所有监控器
datadog monitor get <id> # 检查特定监控器详情
datadog metric query "<monitor-query>" --from 1h # 根据实际数值验证阈值
datadog monitor update <id> --threshold-critical 100 --threshold-warning 80 --renotify 30Set up team-based log tagging
设置基于团队的日志标签
bash
datadog pipeline create --name "Team Tagging" --filter "*" --enabled
datadog pipeline add-category <id> --target team \
--rule "service:(svc-a OR svc-b)=team-alpha" \
--rule "service:(svc-c OR svc-d)=team-beta"
datadog pipeline add-remapper <id> --source team --target team \
--source-type attribute --target-type tagbash
datadog pipeline create --name "Team Tagging" --filter "*" --enabled
datadog pipeline add-category <id> --target team \
--rule "service:(svc-a OR svc-b)=team-alpha" \
--rule "service:(svc-c OR svc-d)=team-beta"
datadog pipeline add-remapper <id> --source team --target team \
--source-type attribute --target-type tagCreate a log-based error rate monitor
创建基于日志的错误率监控器
bash
datadog monitor create --type "log alert" \
--name "My service error rate" \
--formula "errors / total" \
--log-query-error "service:myapp status:error" \
--log-query-total "service:myapp" \
--threshold-critical 0.1 --threshold-warning 0.05 \
--window "5m" --message "@pagerduty-team" --tags "env:prod,team:myteam"bash
datadog monitor create --type "log alert" \
--name "My service error rate" \
--formula "errors / total" \
--log-query-error "service:myapp status:error" \
--log-query-total "service:myapp" \
--threshold-critical 0.1 --threshold-warning 0.05 \
--window "5m" --message "@pagerduty-team" --tags "env:prod,team:myteam"