AI 监控员 Playbook 库
跟 monitoring-ai-employee.md 配对:
AI 监控员触发告警后,按这个 playbook 库决定怎么处理。每个 playbook
是一段 markdown,AI 通过 tool call 读它 + 决定 autofix 或 page 人。
Playbook 设计原则:
- 明确触发条件:metric query + 阈值,AI 容易 grep
- 二元处理:autofix(AI 自己能搞)或 escalate(page 值班人)
- 可逆性优先:autofix 操作必须可回退(restart 而不是 drop)
- 限速:每个 playbook 自带”per N min run K times”上限,避免循环
Playbook index
| 触发 | 严重度 | 处理 | Doc |
|---|---|---|---|
| API p95 latency > 2s for 5min | High | escalate | #api-latency-spike |
| Postgres connections > 80% pool | High | autofix (restart 连接池) | #pg-connection-flood |
| OSS upload error rate > 5% | Medium | escalate to Aliyun ticket | #oss-error-rate |
| Redis OOM evict rate > 10% / min | Medium | autofix (扩容到下一 tier) | #redis-oom |
| Compute cold-start p95 > 5s | Low | escalate (capacity planning) | #compute-cold-start |
| Credit balance per project < ¥1 | Info | autofix (audit_log warn + auto top-up if enabled) | #credit-low |
| Keel bundle download error > 1% (planned) | Medium | autofix (回滚到 stable) | #bundle-error |
| Cert expiry < 30 days | Low | escalate (Caddy 一般自动续) | #cert-expiry |
| New SQL injection attempt log | High | autofix (block IP + audit) | #sql-injection |
| Cost anomaly: project > 200% prev day | High | escalate + freeze project | #cost-spike |
api-latency-spike
Trigger: avg(api_p95_latency_ms) by (route) > 2000 for 5 consecutive minutes.
Action: ESCALATE to human.
AI pre-investigation:
- Read last 100 lines of
mortar-api.logfor the matching route - Check Aliyun status page (RDS + Redis + OSS health)
- Check recent deploys:
git log --since="1 hour ago" - Calculate baseline (median p95 last 7 days) — surfacing % deviation
Page message template:
⚠ Latency spike: <route> p95 = <current> ms (baseline <baseline> ms, +<delta>%)
Started: <UTC time>
Recent deploys: <git short list>
Aliyun: <status — green / amber / red>
Last 5 error lines: <excerpt>
Playbook: oncall-playbooks.md#api-latency-spike
Not autofix because: latency causes are heterogeneous (slow query / connection pool / cache miss / GC pause / upstream cloud) and require human triage.
pg-connection-flood
Trigger: pg_stat_activity.count > 0.8 * max_connections for 2 min.
Action: AUTOFIX — restart the application’s connection pool (forces idle connections to drop).
Steps:
- Pull current
pg_stat_activitysnapshot for audit log - Send SIGHUP to each Mortar replica → triggers connection pool reset (uses graceful drain — in-flight requests finish)
- Wait 60 sec
- Re-check; if still > 80%, escalate
Limit: max 3 runs per hour. Beyond → escalate (suggests slow query holding connections).
oss-error-rate
Trigger: oss_response_5xx_rate > 0.05 for 5 min.
Action: ESCALATE (likely Aliyun-side; we can’t fix).
AI pre-investigation:
- Check Aliyun OSS status page (https://status.aliyun.com)
- Sample 10 failing requests — extract bucket + key + status
- Check if isolated to one region
Note: OSS errors usually self-recover in < 30 min. Don’t autofix unless we know root cause is on our side (bucket policy misconfig etc.).
redis-oom
Trigger: redis_evicted_keys_per_sec > <baseline> * 10 for 10 min.
Action: AUTOFIX — bump Tair capacity to next tier.
Steps:
- Read current Tair tier + memory utilization
- Aliyun API call to upgrade tier (e.g. tiny → small)
- Tair handles online resize transparently (no downtime)
- Verify post-upgrade evict rate drops within 5 min
Cost impact: alert next-day bill review (cost may jump 2x). Limit: max 1 upgrade / day. Beyond → escalate (suggests capacity planning issue, not transient spike).
compute-cold-start
Trigger: compute_cold_start_p95 > 5000 for 30 min.
Action: ESCALATE — capacity planning, AI doesn’t have authority to bump idle pool size.
AI pre-investigation:
- Which function? (group by
function_name) - How many cold starts in window?
- Cost of bumping idle pool: estimate from FC pricing
credit-low
Trigger: credit_balance_yuan < 1.0 for any project.
Action: AUTOFIX — emit credit_low audit event + (if auto_top_up mode) trigger charge.
Steps:
- Write
audit_logrowkind=credit_lowwith project + owner + balance - If
credit_mode = auto_top_up: trigger top-up viapayment.Multi - Owner notification ships out of the audit stream by whatever channel the deploy operator has wired downstream (Slack webhook, log aggregator alert, in-app banner). Mortar itself no longer sends email — the email feature was removed.
Limit: 1 audit event per project per 24 hours (dedup on kind + project).
bundle-error
Trigger: metric to be defined when Keel Update server emits Prometheus stats — planned. Placeholder; the playbook below is the intended response shape once the metric ships.
Action: AUTOFIX — keel rollback --to=<previous-promoted-hash>.
Steps:
- Look up which project is affected (group by
project) - Find previous promoted hash by querying Keel’s
bundlestable for the prior entry under the same(project, platform, channel, runtime_version)tuple — the in-flight rollout’sstaged_hashincurrentsis the current target; the row inbundleswith the most recentuploaded_atbefore that is the rollback target. Seekeel/cloud/internal/update/store.gofor the schema. - Run
keel rollbackfor that project (server-side:Rollback()onManifestStore) - Emit
bundle_rollbackaudit event for downstream owner notification
Limit: 1 auto-rollback per project per 24 hours. Multiple rollbacks suggest bigger problem — escalate.
cert-expiry
Trigger: cron daily; cert.notAfter < now + 30 days.
Action: ESCALATE (Caddy auto-renew is normally fine; alert is for paranoia).
Special: If Caddy hasn’t attempted renewal in last 24h, page immediately (Caddy might be stuck).
sql-injection
Trigger: SQL syntax error patterns in audit log (e.g. UNION SELECT,
DROP TABLE, ;-- in user input).
Action: AUTOFIX — temporary IP block + alert security team.
Steps:
- Extract source IP from request log
- Add to rate-limiter denylist for 24 hours
- Record in audit log with
severity=critical - Page security on-call (not normal on-call)
Special: Don’t autofix if same IP appears > 100 times — that’s distributed attack, needs human + 阿里云 anti-DDoS coordination.
cost-spike
Trigger: project_credits_used_today > 2 * project_credits_used_yesterday AND today_credits > 100 yuan.
Action: ESCALATE + freeze project (autofix).
Steps:
- Emit
cost_anomalyaudit event (owner notification routes through whatever channel the operator has wired on the audit stream) - Set project
credit_mode = hard_budget+ log incident; user must intervene to top up - Subsequent API calls hit credit-gate 402
- Page customer success team — manual review
Why autofix freeze: Mortar’s hard-budget gate is the safety net against rogue infinite-loop functions burning customer’s account. Pause first, ask later. (Current credit model is single-dimension: only credit exists; no monthly_cap / hourly cap fields — top-up is the only path back to writable.)
Adding a new playbook
When you add a new alert rule, write the playbook here. Format:
## <slug>
**Trigger**: <metric expression>
**Action**: AUTOFIX | ESCALATE
**Steps**: numbered list of actions
**Limit**: rate-limit + "beyond → escalate" rule
**Why** (if autofix): justify the reversibility
AI 监控员通过 tool call 读 oncall-playbooks.md 的 # heading 列
表,匹配 slug,按 “Action” 字段决定行为。新 playbook 加到这里 + AI
下次告警就用上,不需要 redeploy。
扩展计划(规划中)
- 跨产品 playbook(Fabric / Keel / Mortar 共享)
- Playbook 版本化 — 记录每次 autofix 的”按 v3 of playbook X”
- 月度 incident review 自动总结 + 改进 playbook