datadog-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Datadog 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"
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
--site
flag:
bash
npx @leoflores/datadog-cli logs search --query "*" --site datadoghq.eu
bash
npx @leoflores/datadog-cli <command>
对于非美国区的Datadog站点,使用
--site
参数:
bash
npx @leoflores/datadog-cli logs search --query "*" --site datadoghq.eu

Commands Overview

命令概览

CommandDescription
logs search
Search logs with filters
logs tail
Stream logs in real-time
logs trace
Find logs for a distributed trace
logs context
Get logs before/after a timestamp
logs patterns
Group similar log messages
logs compare
Compare log counts between periods
logs multi
Run multiple queries in parallel
logs agg
Aggregate logs by facet
metrics query
Query timeseries metrics
errors
Quick error summary by service/type
services
List services with log activity
dashboards
Manage dashboards (CRUD)
dashboard-lists
Manage dashboard lists
命令描述
logs search
使用过滤器搜索日志
logs tail
实时流式查看日志
logs trace
查找分布式追踪对应的日志
logs context
获取指定时间戳前后的日志
logs patterns
分组相似的日志消息
logs compare
对比不同时间段的日志数量
logs multi
并行运行多个查询
logs agg
按维度聚合日志
metrics query
查询时间序列指标
errors
按服务/类型快速汇总错误
services
列出有日志活动的服务
dashboards
管理仪表板(增删改查)
dashboard-lists
管理仪表板列表

Quick Examples

快速示例

Search Errors

搜索错误

bash
npx @leoflores/datadog-cli logs search --query "status:error" --from 1h --pretty
bash
npx @leoflores/datadog-cli logs search --query "status:error" --from 1h --pretty

Tail Logs (Real-time)

实时查看日志

bash
npx @leoflores/datadog-cli logs tail --query "service:api status:error" --pretty
bash
npx @leoflores/datadog-cli logs tail --query "service:api status:error" --pretty

Error Summary

错误汇总

bash
npx @leoflores/datadog-cli errors --from 1h --pretty
bash
npx @leoflores/datadog-cli errors --from 1h --pretty

Trace Correlation

追踪关联

bash
npx @leoflores/datadog-cli logs trace --id "abc123def456" --pretty
bash
npx @leoflores/datadog-cli logs trace --id "abc123def456" --pretty

Query Metrics

查询指标

bash
npx @leoflores/datadog-cli metrics query --query "avg:system.cpu.user{*}" --from 1h --pretty
bash
npx @leoflores/datadog-cli metrics query --query "avg:system.cpu.user{*}" --from 1h --pretty

Compare Periods

对比时间段

bash
npx @leoflores/datadog-cli logs compare --query "status:error" --period 1h --pretty
bash
npx @leoflores/datadog-cli logs compare --query "status:error" --period 1h --pretty

Global Flags

全局参数

FlagDescription
--pretty
Human-readable output with colors
--output <file>
Export results to JSON file
--site <site>
Datadog site (e.g.,
datadoghq.eu
)
参数描述
--pretty
带颜色的人类可读格式输出
--output <file>
将结果导出为JSON文件
--site <site>
Datadog站点(例如:
datadoghq.eu

Time Formats

时间格式

  • Relative:
    30m
    ,
    1h
    ,
    6h
    ,
    24h
    ,
    7d
  • ISO 8601:
    2024-01-15T10:30:00Z
  • 相对时间
    30m
    ,
    1h
    ,
    6h
    ,
    24h
    ,
    7d
  • ISO 8601格式
    2024-01-15T10:30:00Z

Incident Triage Workflow

事件分类工作流

bash
undefined
bash
undefined

1. 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)。