构建高效 On-Call 体系:从事后复盘到主动防御
· 更新于 2026-07-26
⏱️ 阅读约 2 分钟 (718 字)
On-Call
技术管理
SRE
从告警策略设计、值班排班管理到故障响应流程,系统化构建高效的 On-Call 体系,实现从被动救火到主动防御的转变。
一、On-Call 体系设计
高效的 On-Call 体系不仅仅是安排值班表,更需要完善的告警分级、升级策略和故障响应流程。目标是减少告警疲劳,同时确保关键故障不被遗漏。
二、PagerDuty 配置与自动化
以下是一个 PagerDuty 服务配置示例和配套的自动化脚本。
PagerDuty 服务配置
# PagerDuty 服务与升级策略配置
service:
name: "production-critical"
escalation_policy: "sre-primary"
alert_grouping:
type: "time"
timeout: 300 # 5分钟内同类告警归组
auto_resolve_timeout: 600 # 10分钟自动解决
urgency_rule:
type: "use_support_hours"
support_hours:
timezone: "Asia/Shanghai"
start_time: "09:00"
end_time: "18:00"
days_of_week: [1, 2, 3, 4, 5]
escalation_rules:
- targets: ["on-call-primary"]
escalation_timeout: 15 # 15分钟未确认
- targets: ["on-call-secondary"]
escalation_timeout: 10
- targets: ["sre-manager"]
escalation_timeout: 5
yaml
# PagerDuty 服务与升级策略配置
service:
name: "production-critical"
escalation_policy: "sre-primary"
alert_grouping:
type: "time"
timeout: 300 # 5分钟内同类告警归组
auto_resolve_timeout: 600 # 10分钟自动解决
urgency_rule:
type: "use_support_hours"
support_hours:
timezone: "Asia/Shanghai"
start_time: "09:00"
end_time: "18:00"
days_of_week: [1, 2, 3, 4, 5]
escalation_rules:
- targets: ["on-call-primary"]
escalation_timeout: 15 # 15分钟未确认
- targets: ["on-call-secondary"]
escalation_timeout: 10
- targets: ["sre-manager"]
escalation_timeout: 5On-Call 自动化 Shell 脚本
#!/bin/bash
# On-Call 交接检查脚本
set -euo pipefail
echo "=== On-Call 交接清单 ==="
# 检查待处理告警
ALERTS=$(curl -s -H "Authorization: Token ${PD_API_TOKEN}" \
"https://api.pagerduty.com/incidents?statuses[]=triggered&statuses[]=acknowledged" \
| jq '.incidents | length')
echo "待处理告警数: ${ALERTS}"
if [ "${ALERTS}" -gt 0 ]; then
echo "警告:存在未解决的告警,请在交接前处理!"
exit 1
fi
# 检查变更窗口
echo "检查正在进行的变更..."
kubectl get deployments --all-namespaces \
-o json | jq -r '.items[] | select(.metadata.annotations["change/in-progress"]=="true") | .metadata.namespace + "/" + .metadata.name' \
|| echo "无进行中的变更"
echo "=== 交接检查完成 ==="
bash
#!/bin/bash
# On-Call 交接检查脚本
set -euo pipefail
echo "=== On-Call 交接清单 ==="
# 检查待处理告警
ALERTS=$(curl -s -H "Authorization: Token ${PD_API_TOKEN}" \
"https://api.pagerduty.com/incidents?statuses[]=triggered&statuses[]=acknowledged" \
| jq '.incidents | length')
echo "待处理告警数: ${ALERTS}"
if [ "${ALERTS}" -gt 0 ]; then
echo "警告:存在未解决的告警,请在交接前处理!"
exit 1
fi
# 检查变更窗口
echo "检查正在进行的变更..."
kubectl get deployments --all-namespaces \
-o json | jq -r '.items[] | select(.metadata.annotations["change/in-progress"]=="true") | .metadata.namespace + "/" + .metadata.name' \
|| echo "无进行中的变更"
echo "=== 交接检查完成 ==="三、事后复盘与主动防御
每次故障后应进行无指责的事后复盘,记录时间线、根因和改进措施。通过建立混沌工程实验和持续性能压测,将 On-Call 从被动救火转向主动防御。
本文作者:技术领航员 | 许可协议:CC BY-NC-SA 4.0
本文链接:https://sre-ai-blog.pages.dev/zh/posts/incident-management/(转载请注明出处)