mcpField
D
dd-audit-cost-spike-investigation

dd-audit-cost-spike-investigation

github.com/datadog-labs云与 DevOps180476 次安装6 天前更新
代码仓库

关于 dd-audit-cost-spike-investigation

用于调查 Datadog 用量激增的技能,通过用量计量数据与 Audit Trail 配置变更进行关联。适合排查成本上升的团队;它关注配置变更,不追踪具体数据由谁或哪个进程提交。

主要功能

  1. 01按时间和产品类别定位用量激增
  2. 02搜索激增前的 Audit Trail 变更
  3. 03按产品类别筛选变更
  4. 04说明调查范围及后续排查方向

适用场景

  1. 01调查用量激增前发生的配置变更
  2. 02将日志或 APM 用量增长关联到相关变更
  3. 03未发现配置变更时排查其他原因

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/datadog-labs/agent-skills --skill dd-audit-cost-spike-investigation

安装后在 Claude Code 中输入/dd-audit-cost-spike-investigation确认已加载。

详细介绍

审计跟踪:成本/用量激增调查

通过关联账单数据与配置变更历史,找出导致 Datadog 用量激增的原因。

因果链为:有人更改了某项配置 → 该变更增加了数据量 → 用量激增 → 成本上升。用量计量会告诉你何时发生了什么;审计跟踪则会告诉你是谁做出了变更。

前提条件

pup auth login   # OAuth2 (recommended) — covers audit queries
# Usage Metering queries also need DD_API_KEY + DD_APP_KEY
export DD_API_KEY=<your-api-key>
export DD_APP_KEY=<your-app-key>
export DD_SITE=datadoghq.com

范围界定

此技能用于识别可能导致用量激增的配置变更。它不会识别具体是哪个用户或进程提交了数据(例如,哪个服务发送了 LLM spans)。如需按提交来源进行归因,请使用 LLM Observability traces 或 APM instrumentation。

调查工作流

第 1 步 — 确定激增时段和产品类别
START=$(date -u -v-7d +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null || date -u -d "7 days ago" +"%Y-%m-%dT%H:%M:%SZ")
END=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

curl -s -G "https://api.${DD_SITE}/api/v2/usage/hourly_usage" \
  -H "DD-API-KEY: ${DD_API_KEY}" \
  -H "DD-APPLICATION-KEY: ${DD_APP_KEY}" \
  --data-urlencode "filter[timestamp][start]=${START}" \
  --data-urlencode "filter[timestamp][end]=${END}" \
  --data-urlencode "filter[product_families]=all" \
  | jq '[.data[] | {
      timestamp: .attributes.timestamp,
      product: .attributes.product_family,
      measurements: [.attributes.measurements[] | {type: .usage_type, value: .value}]
    }]'

涵盖 LLM/AI 的产品类别: llm_observability、bits_ai、logs、apm

第 2 步 — 定位激增时间

根据第 1 步,找出用量突增的小时/日期。将时间戳记为 SPIKE_TIME。

第 3 步 — 搜索激增前 24 小时内的审计跟踪配置变更
pup audit-logs search \
  --query "@action:(created OR modified OR deleted)" \
  --from "SPIKE_TIME_MINUS_24H" \
  --to "SPIKE_TIME" \
  --limit 200 \
  -o json \
  | jq '[.data[] | {
      timestamp: .attributes.timestamp,
      user: .attributes.attributes.usr.email,
      actor_type: .attributes.attributes.evt.actor.type,
      action: .attributes.attributes.action,
      event_category: .attributes.attributes.evt.name,
      resource_type: .attributes.attributes.asset.type,
      resource_id: .attributes.attributes.asset.id
    }]'

注意: --from 和 --to 可接受 ISO 时间戳(例如 2026-05-01T14:00:00Z)或相对时间值(1h、24h、7d)。

第 4 步 — 筛选与产品相关的配置变更

筛选最可能影响用量激增产品的审计类别:

如果用量激增的产品是添加到查询中
llm_observability@evt.name:(Integration OR APM OR "Log Management")
logs / indexed_logs@evt.name:"Log Management" @asset.type:(pipeline OR index OR exclusion_filter)
apm / indexed_spans@evt.name:APM @asset.type:(retention_filter OR sampling_rate)
rum@evt.name:RUM
metrics@evt.name:Metrics

LLM Observability 用量激增示例:

pup audit-logs search \
  --query "@evt.name:(Integration OR APM OR \"Log Management\") @action:(created OR modified)" \
  --from "SPIKE_TIME_MINUS_24H" \
  --to "SPIKE_TIME" \
  --limit 100 \
  -o json \
  | jq '[.data[] | {
      timestamp: .attributes.timestamp,
      user: .attributes.attributes.usr.email,
      action: .attributes.attributes.action,
      category: .attributes.attributes.evt.name,
      resource_type: .attributes.attributes.asset.type,
      resource_id: .attributes.attributes.asset.id
    }]'

输出格式

Usage spike detected:
  Product: <product_family>
  Spike time: <SPIKE_TIME>
  Volume: <baseline> → <spike_value> (<magnitude>×)

Configuration changes in 24h preceding spike:
  <timestamp> | <user_email> | <action> <resource_type> <resource_id> | <category>

Likely causal change: <most-proximate change matching the product family>

Confidence: HIGH (single clear change) / MEDIUM (multiple candidates) / LOW (no matching changes)

Next steps:
  - Confirm with <user_email> whether the change was intentional
  - If unintentional: revert <resource_id> and monitor volume
  - If intentional: update cost forecasts and alert thresholds

未发现因果变更时

  1. 变更可能早于 24 小时的时间窗口——将范围扩大到 72 小时
  2. 增长可能源于应用端 instrumentation 变更——检查部署记录
  3. 增长可能由自然流量增长导致——与产品发布或流量事件进行关联

参考资料

评论

支持 Markdown