Skip to Content
流程Fly Audit

Fly Audit · 监控与告警

fly-audit 是独立的 fly app,负责审计 personal org 全部 fly 资源、估算月度花费、检测孤立资源, 通过 Telegram 推送日审与即时告警。

数据流

┌────────────────────────────────────────────────────────────────────────────┐ │ fly-audit machine │ │ │ │ ┌──────────────────┐ ┌────────────────────────────────────────────┐ │ │ │ node-cron │ │ node:http server :3000 │ │ │ │ │ │ POST /telegram/webhook │ │ │ │ 6h: auditCycle │ │ GET /health │ │ │ │ 9:00 JST: daily │ └────────────────┬───────────────────────────┘ │ │ └────────┬─────────┘ │ │ │ │ │ │ │ ▼ ▼ │ │ ┌────────────────────┐ ┌──────────────────────┐ │ │ │ FlyApiClient │ │ Webhook Handler │ │ │ │ (Machines API + │ │ • verify secret │ │ │ │ GraphQL) │ │ • verify chat_id │ │ │ └────────┬───────────┘ │ • dispatch /status │ │ │ │ │ /cost │ │ │ ▼ │ /help │ │ │ ┌────────────────────┐ └──────────┬───────────┘ │ │ │ cost-estimator │ │ │ │ │ + prices.yaml │ │ │ │ └────────┬───────────┘ │ │ │ │ │ │ │ ▼ ▼ │ │ ┌────────────────────┐ ┌──────────────────────┐ │ │ │ SQLite WAL ◄─────────┤ TelegramService │ │ │ │ - snapshots │ │ (Bot API direct) │ │ │ │ - alert_events │ └──────────┬───────────┘ │ │ │ /data/fly-audit.db │ │ │ │ └─────────────────────┘ │ │ │ │ │ └──────────────────────────────────────────────┼──────────────────────────────┘ Telegram (你) │ (心跳超时回推) healthchecks.io email

8 维风险覆盖矩阵

维度覆盖方式实现位置
stopped machine 烧 rootfs立即告警(≥24h, primary apps)alert-rules.ts#detectStoppedMachines
孤立 volume立即告警alert-rules.ts#detectOrphanVolumes
孤立 Postgres通过 stopped machine 间接覆盖同上
孤立 IPv4立即告警alert-rules.ts#detectOrphanIpv4
Egress spike(总量)snapshot diff 体现于日审daily-digest.ts
Egress region 分桶add-egress-region-label未实现
Autoscaler 失控snapshot diff 体现 machine 增量同上
Postgres tier 误配仅日审 cost 显示,无连接数待 follow-up

详细推断逻辑见 openspec/changes/add-fly-audit-telegram/design.md 的 D7 / D9 / D10。

优先级路由

App优先级stopped_24h 行为
openspec-apiprimary立即告警
openspec-dbprimary立即告警
ai-slide-serversecondary仅日审 digest
ai-slide-dbsecondary仅日审 digest
ai-slide-export-pptxsecondary仅日审 digest
fly-auditsecondary仅日审 digest (自指)

修改:apps/fly-audit/src/app-priority.ts

单价表来源

apps/fly-audit/src/prices.yaml 当前快照:2026-05-14,来源 fly.io/docs/about/pricing/ 

修改流程:

  1. 拉最新 fly 价格页
  2. prices.yamlversion 字段
  3. pnpm test 验证 cost-estimator 测试通过
  4. PR review
  5. merge → flyctl deploy -a fly-audit

告警去重逻辑

fly_alert_event 表按 dedup_key 唯一索引:

告警类型dedup_key 形态窗口
stopped_24hstopped_24h:{machine_id}24h
orphan_volumeorphan_volume:{volume_id}24h
orphan_ipv4orphan_ipv4:{ip}24h
daily_digestdaily_digest24h

同 dedup_key 在 24h 内不再发送。first_seen 保留首次触发时间。

自监控(防递归故障)

监控系统自身挂了谁告警?答:healthchecks.io 外部 heartbeat

正常路径: fly-audit cron 完成 → ping https://hc-ping.com/<uuid> healthchecks.io 记录最近 ping 时间 故障路径: fly-audit 崩溃 / 进程死 → 不再 ping 超过 7h(6h schedule + 1h grace)→ healthchecks.io 主动发邮件

注意:

  • 仅在完整 audit / digest 成功时 ping(包括 Telegram 推送成功)
  • 任一步失败 → 不 ping → 让 7h 后 healthchecks 主动告警

运维 SOP

apps/fly-audit/README.md 

相关文档

  • 设计 / 决策:openspec/changes/add-fly-audit-telegram/design.md
  • 规范:openspec/changes/add-fly-audit-telegram/specs/fly-audit/spec.md
  • 任务清单:openspec/changes/add-fly-audit-telegram/tasks.md
  • 起源调研:Fly.io 监控能力与实施可行性 · 2026Q2