技能 编程开发 成本追踪数据导出

成本追踪数据导出

v20261029
cost-export
此技能将成本追踪遥测数据导出为 Prometheus 文本文件或 Webhook JSON 格式,适用于 Grafana、Datadog 等外部可观测性系统。它从 cost-tracking 命名空间拉取会话和预算记录,支持定时刷新仪表盘或一次性 webhook 报告,实现成本数据的实时监控与灵活汇报。
获取技能
93 次下载
概览

Cost Export

Pulls every session-* and budget-config-* record from cost-tracking and emits in formats consumable by external observability systems. Without this, cost data lives only inside the AgentDB namespace; with it, the same data lights up dashboards.

When to use

  • After any cost-track run, to refresh metrics for Grafana / Datadog / Prometheus.
  • Cron-friendly via /loop 5m to keep external dashboards near-real-time.
  • One-shot to a webhook for ad-hoc reporting (Slack, custom endpoint).

Steps

  1. Pick a format — textfile collector for Prometheus / Grafana, or webhook POST for everything else:

```bash

Prometheus node_exporter textfile collector

node plugins/ruflo-cost-tracker/scripts/export.mjs --prometheus /var/lib/nodeexporter/textfilecollector/cost_tracker.prom

Webhook (POSTs JSON; add auth via env)

EXPORTWEBHOOKHEADER='Authorization: Bearer $TOKEN' \
node plugins/ruflo-cost-tracker/scripts/export.mjs --webhook https://hooks.example.com/cost-tracker

Stdout JSON (default if no flag)

node plugins/ruflo-cost-tracker/scripts/export.mjs
```

  1. Inspect what's emitted — Prometheus output includes:

```
costtrackertotal_usd
costtrackertiertotalusd{tier="opus|sonnet|haiku"}
costtrackersessiontotalusd{session="<8-char>"}
costtrackersession_messages{session="<8-char>"}
costtrackerbudget_usd (if budget configured)
costtrackerbudget_utilization (spent / budget)
```

  1. Webhook payload shape — the JSON the webhook receives matches the stdout JSON: { exportedAt, sessions: [...], budget, totalUsd, byTier }. Headers may be added via EXPORT_WEBHOOK_HEADER='K1: V1, K2: V2' (comma-separated).

Env overrides

EnvDefaultPurpose
EXPORT_NAMESPACEcost-trackingOverride target namespace
EXPORT_WEBHOOK_HEADERunsetComma-separated K: V pairs for webhook auth
EXPORT_QUIET=1unsetSuppress non-error confirmation output

Cross-references

  • cost-track — produces the data this skill exports
  • cost-budget-check — the same cost_tracker_budget_* metrics are alertable in Prometheus
  • node_exporter textfile collector docs (Prometheus convention) — drop the .prom file in the collector directory and Prometheus picks it up
信息
分类 编程开发
名称 cost-export
版本 v20261029
大小 2.73KB
更新时间 2026-10-30
语言