cost-export
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCost Export
成本导出
Pulls every and record from 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.
session-*budget-config-*cost-tracking从中提取所有和记录,并以外部可观测系统可消费的格式输出。如果没有该功能,成本数据仅存储在AgentDB命名空间内;有了它,这些数据可以用于点亮仪表板。
cost-trackingsession-*budget-config-*When to use
使用场景
- After any cost-track run, to refresh metrics for Grafana / Datadog / Prometheus.
- Cron-friendly via to keep external dashboards near-real-time.
/loop 5m - One-shot to a webhook for ad-hoc reporting (Slack, custom endpoint).
- 每次成本追踪运行完成后,刷新Grafana / Datadog / Prometheus的指标。
- 通过实现 cron 友好的定时执行,让外部仪表板接近实时更新。
/loop 5m - 一次性发送到Webhook以进行临时报告(如Slack、自定义端点)。
Steps
操作步骤
-
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/node_exporter/textfile_collector/cost_tracker.prom # Webhook (POSTs JSON; add auth via env) EXPORT_WEBHOOK_HEADER='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 -
Inspect what's emitted — Prometheus output includes:
cost_tracker_total_usd <gauge> cost_tracker_tier_total_usd{tier="opus|sonnet|haiku"} <gauge> cost_tracker_session_total_usd{session="<8-char>"} <gauge> cost_tracker_session_messages{session="<8-char>"} <counter> cost_tracker_budget_usd <gauge> (if budget configured) cost_tracker_budget_utilization <gauge> (spent / budget) -
Webhook payload shape — the JSON the webhook receives matches the stdout JSON:. Headers may be added via
{ exportedAt, sessions: [...], budget, totalUsd, byTier }(comma-separated).EXPORT_WEBHOOK_HEADER='K1: V1, K2: V2'
-
选择格式 — 用于Prometheus / Grafana的文本文件收集器格式,或用于其他系统的Webhook POST格式:bash
# Prometheus node_exporter文本文件收集器 node plugins/ruflo-cost-tracker/scripts/export.mjs --prometheus /var/lib/node_exporter/textfile_collector/cost_tracker.prom # Webhook(POST JSON格式;通过环境变量添加认证) EXPORT_WEBHOOK_HEADER='Authorization: Bearer $TOKEN' \ node plugins/ruflo-cost-tracker/scripts/export.mjs --webhook https://hooks.example.com/cost-tracker # 标准输出JSON(无标志时的默认格式) node plugins/ruflo-cost-tracker/scripts/export.mjs -
检查输出内容 — Prometheus输出包含:
cost_tracker_total_usd <gauge> cost_tracker_tier_total_usd{tier="opus|sonnet|haiku"} <gauge> cost_tracker_session_total_usd{session="<8-char>"} <gauge> cost_tracker_session_messages{session="<8-char>"} <counter> cost_tracker_budget_usd <gauge> (若配置了预算) cost_tracker_budget_utilization <gauge> (已花费/预算) -
Webhook负载结构 — Webhook接收的JSON与标准输出的JSON一致:。可通过
{ exportedAt, sessions: [...], budget, totalUsd, byTier }添加请求头(逗号分隔)。EXPORT_WEBHOOK_HEADER='K1: V1, K2: V2'
Env overrides
环境变量覆盖
| Env | Default | Purpose |
|---|---|---|
| | Override target namespace |
| unset | Comma-separated |
| unset | Suppress non-error confirmation output |
| 环境变量 | 默认值 | 用途 |
|---|---|---|
| | 覆盖目标命名空间 |
| 未设置 | 用于Webhook认证的逗号分隔 |
| 未设置 | 抑制非错误的确认输出 |
Cross-references
交叉引用
- — produces the data this skill exports
cost-track - — the same
cost-budget-checkmetrics are alertable in Prometheuscost_tracker_budget_* - node_exporter textfile collector docs (Prometheus convention) — drop the file in the collector directory and Prometheus picks it up
.prom
- — 生成该技能导出的数据
cost-track - — 相同的
cost-budget-check指标可在Prometheus中设置告警cost_tracker_budget_* - node_exporter文本文件收集器文档(Prometheus规范)—— 将文件放入收集器目录,Prometheus会自动获取
.prom