实战场景配方(Cookbook)
以下 4 份配置均来自真实生产排障场景,可直接复制到 config.yml 运行,生成 AI Agent 开箱直读的全貌故障 Context。
配方 1:微服务慢请求与报错四维联动(APM + 日志 + 宿主机)
Section titled “配方 1:微服务慢请求与报错四维联动(APM + 日志 + 宿主机)”痛点:核心交易接口突然 P99 飙升或 5xx 暴涨,传统排障要在监控图表、链路追踪、Kibana 日志和 SSH top 之间来回切换,等凑齐线索时现场早已过去。
global: interval: 5s eval_interval: 1s before: 60s after: 20s
inputs: host: - id: default log_file: - id: order_app path: /var/log/order/app.log apm: - id: order_svc http_listen: "127.0.0.1:4318" slow_threshold_ms: 500
alerts: - id: order_p99_or_err_burst severity: critical for: 15s expr: 'last("apm.order_svc.latency_p99_ms") > 1000 || log_count("log_file.order_app", "ERROR|panic", 60) >= 5' attach: ["host/default"]触发后会发生什么?
- 产出一份自包含的 Markdown Context,同时汇聚:
apm/order_svc与host/default前 60s + 后 20s 全精度指标曲线;- Top 慢/错 Trace 调用链瀑布(含 HTTP/RPC/DB 耗时与异常堆栈);
- 通过
trace_id反向关联的order_app业务报错日志原文; - T0 瞬间宿主机 Top 进程现场。
- 直接交给 Ketos Cloud AI 或本地 AI Agent,一句话定位是慢 SQL、下游超时还是宿主机 CPU/内存瓶颈。
配方 2:抓拍偶发 CPU / 内存尖刺的“短命元凶”
Section titled “配方 2:抓拍偶发 CPU / 内存尖刺的“短命元凶””痛点:半夜收到 CPU 飙高或内存告警,等 SSH 登上去执行 top 时,定时跑批脚本或内存泄漏进程早已退出或被 OOM Killer 干掉,查无实据。
global: interval: 2s eval_interval: 1s before: 60s after: 20s
inputs: host: - id: default top_processes_limit: 15
alerts: - id: cpu_or_mem_spike severity: critical for: 10s expr: 'avg("cpu.usage_pct", 30) > 85 || last("mem.usage_pct") > 85'触发后会发生什么?
- 在
T=0(刚越限满 10s)瞬间单次扫描进程表,自动按触发维度排序(CPU 告警按 CPU 排、内存告警按内存排、同时越限则合并去重 Top CPU + Top Memory); - 落盘至
data/snapshots/cpu_or_mem_spike/host_default_<ts>_firing.md,完整保留短命肇事进程与前后资源趋势。
配方 3:远端 API 超时/502 时,联动拍下本机网络与负载现场
Section titled “配方 3:远端 API 超时/502 时,联动拍下本机网络与负载现场”痛点:核心业务接口偶发超时,研发说“接口没问题”,运维说“机房网络抖了”,需要同时看清远端拨测分段时延(DNS / TLS / TTFB)和本机网卡丢包/负载。
global: interval: 5s eval_interval: 1s
inputs: host: - id: default http_probe: - id: checkout_api url: https://api.example.com/v1/health timeout: 3s expected_status: 200
alerts: # 普通可用性告警:仅拍 checkout_api 曲线,不夹带无关主机数据 - id: checkout_api_down severity: critical for: 10s expr: 'last("http_probe.checkout_api.up") == 0'
# 慢响应深度排障:通过 attach 显式附拍本机 host/default(含网络错误/丢包与 Top 进程) - id: checkout_api_slow severity: warning for: 15s before: 120s after: 30s expr: 'avg("http_probe.checkout_api.latency_ms", 60) > 1200' attach: ["host/default"]效果:checkout_api_slow 生成的单份 .md 里会同时包含 ## Metrics: http_probe/checkout_api、## Metrics: host/default 和 ## Forensic: host/top_processes,一眼区分是 DNS/TLS 慢、远端 TTFB 慢,还是本机 CPU/网卡打满。
配方 4:边缘/IoT 弱网设备的 30MB 闪存保底自治
Section titled “配方 4:边缘/IoT 弱网设备的 30MB 闪存保底自治”痛点:门店/工控边缘盒子内存小、SD 卡怕写穿、经常断网,需要严格限制磁盘占用,同时在容器内监控宿主机状态。
global: interval: 5s eval_interval: 2s before: 30s after: 10s
inputs: host: - id: edge_box root_path: /hostfs mount_point: / top_processes_limit: 10
alerts: - id: edge_disk_full severity: critical every: 15s for: 30s expr: 'last("host.edge_box.disk.usage_pct") > 85 || last("host.edge_box.disk.inode_usage_pct") > 85'
- id: edge_mem_oom_risk severity: critical for: 10s expr: 'last("host.edge_box.mem.usage_pct") > 90'
storage: dir: /var/lib/ketos-agent max_disk_mb: 30 max_snapshots: 200效果:平时 0 磁盘写入;断网期间照常本地自治抓拍,磁盘占用严格锁在 30MB / 200 份 以内,超限自动按时间 FIFO 淘汰最老快照。