关于 slo-implementation
为服务可靠性目标制定与实施提供指导的技能,面向负责可靠性工作的团队,涵盖 SLI、SLO、错误预算、Prometheus 规则和告警。
主要功能
- 01定义可用性与延迟 SLI
- 02设定 SLO 与错误预算
- 03提供 Prometheus 记录规则
- 04配置多窗口燃烧率告警
- 05规划定期 SLO 评审
适用场景
- 01为服务制定可靠性目标
- 02跟踪错误预算消耗
- 03设置基于 SLO 的告警
- 04定期审查可靠性指标
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ sickn33/ agentic-awesome-skills --skill slo-implementation安装后在 Claude Code 中输入/slo-implementation确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
references/error-budget.mdslo-definitions.mdresources/implementation-playbook.md详细介绍
SLO 实施
用于定义和实施服务级别指标(SLI)、服务级别目标(SLO)和错误预算的框架。
不要在以下情况下使用此技能
- 任务与 SLO 实施无关
- 你需要使用此范围之外的其他领域或工具
说明
- 明确目标、约束和所需输入。
- 应用相关最佳实践并验证结果。
- 提供可执行的步骤和验证方法。
- 如需详细示例,请打开
resources/implementation-playbook.md。
用途
使用 SLI、SLO 和错误预算设定可衡量的可靠性目标,在可靠性与创新速度之间取得平衡。
在以下情况下使用此技能
- 定义服务可靠性目标
- 衡量用户感知的可靠性
- 实施错误预算
- 创建基于 SLO 的告警
- 跟踪可靠性目标
SLI/SLO/SLA 层级
SLA (Service Level Agreement)
↓ Contract with customers
SLO (Service Level Objective)
↓ Internal reliability target
SLI (Service Level Indicator)
↓ Actual measurement
定义 SLI
常见的 SLI 类型
1. 可用性 SLI
# Successful requests / Total requests
sum(rate(http_requests_total{status!~"5.."}[28d]))
/
sum(rate(http_requests_total[28d]))
2. 延迟 SLI
# Requests below latency threshold / Total requests
sum(rate(http_request_duration_seconds_bucket{le="0.5"}[28d]))
/
sum(rate(http_request_duration_seconds_count[28d]))
3. 写入成功率 SLI
# Successful writes / Total writes
sum(increase(storage_writes_successful_total[28d]))
/
sum(increase(storage_writes_total[28d]))
**参考:**参见 references/slo-definitions.md
设定 SLO 目标
可用性 SLO 示例
以下停机时间等值假设使用基于时间的 SLI、30 天的月份和 365 天的年份;如果没有流量模型,请勿将基于请求的预算换算为停机时间。
| SLO % | 每月停机时间 | 每年停机时间 |
|---|---|---|
| 99% | 7.2 小时 | 3.65 天 |
| 99.9% | 43.2 分钟 | 8.76 小时 |
| 99.95% | 21.6 分钟 | 4.38 小时 |
| 99.99% | 4.32 分钟 | 52.56 分钟 |
选择合适的 SLO
考虑因素:
- 用户期望
- 业务需求
- 当前性能
- 可靠性成本
- 竞争对手基准
SLO 示例:
slos:
- name: api_availability
target: 99.9
window: 28d
sli: |
sum(rate(http_requests_total{status!~"5.."}[28d]))
/
sum(rate(http_requests_total[28d]))
- name: api_latency_under_500ms
target: 99
window: 28d
sli: |
sum(rate(http_request_duration_seconds_bucket{le="0.5"}[28d]))
/
sum(rate(http_request_duration_seconds_count[28d]))
错误预算计算
错误预算公式
Error Budget = 1 - SLO Target
示例:
- SLO:99.9% 可用性
- 错误预算:0.1% = 每月 43.2 分钟
- 当前错误:0.05% = 每月 21.6 分钟
- 剩余预算:50%
错误预算政策
error_budget_policy:
- remaining_budget: 100%
action: Normal development velocity
- remaining_budget: 50%
action: Consider postponing risky changes
- remaining_budget: 10%
action: Freeze non-critical changes
- remaining_budget: 0%
action: Feature freeze, focus on reliability
**参考:**参见 references/error-budget.md
SLO 实施
Prometheus 记录规则
# SLI Recording Rules
groups:
- name: sli_rules
interval: 30s
rules:
# Availability SLI
- record: sli:http_availability:ratio
expr: |
sum(rate(http_requests_total{status!~"5.."}[28d]))
/
sum(rate(http_requests_total[28d]))
# Latency SLI (requests < 500ms)
- record: sli:http_latency:ratio
expr: |
sum(rate(http_request_duration_seconds_bucket{le="0.5"}[28d]))
/
sum(rate(http_request_duration_seconds_count[28d]))
- name: slo_rules
interval: 5m
rules:
# SLO compliance (1 = meeting SLO, 0 = violating)
- record: slo:http_availability:compliance
expr: sli:http_availability:ratio >= bool 0.999
- record: slo:http_latency:compliance
expr: sli:http_latency:ratio >= bool 0.99
# Error budget remaining (percentage)
- record: slo:http_availability:error_budget_remaining
expr: |
(sli:http_availability:ratio - 0.999) / (1 - 0.999) * 100
# Error budget burn rate
- record: slo:http_availability:burn_rate_5m
expr: |
(1 - (
sum(rate(http_requests_total{status!~"5.."}[5m]))
/
sum(rate(http_requests_total[5m]))
)) / (1 - 0.999)
以下预算耗尽预测假设近期消耗速率恒定。消耗速率为零时,不存在有限的耗尽时间;预算已耗尽时,应显示为已耗尽。遥测数据缺失不代表流量健康。
确保零错误计数器已初始化,或使用同一组正常事件/总事件数据推导异常事件。缺失的 5xx 序列不得悄然导致消耗率/合规性规则失效;应分别测试零错误、无流量和遥测数据缺失的情况。
其他消耗率记录规则
使用告警示例前,请将这些规则加入同一记录规则组:
- record: slo:http_availability:burn_rate_1h
expr: (sum(rate(http_requests_total{status=~"5.."}[1h])) / sum(rate(http_requests_total[1h]))) / (1 - 0.999)
- record: slo:http_availability:burn_rate_6h
expr: (sum(rate(http_requests_total{status=~"5.."}[6h])) / sum(rate(http_requests_total[6h]))) / (1 - 0.999)
- record: slo:http_availability:burn_rate_30m
expr: (sum(rate(http_requests_total{status=~"5.."}[30m])) / sum(rate(http_requests_total[30m]))) / (1 - 0.999)
SLO 告警规则
groups:
- name: slo_alerts
interval: 1m
rules:
# Fast burn: 14.4x rate, 1 hour window
# Approximately 2.14% of a 28-day budget in 1 hour at constant traffic
- alert: SLOErrorBudgetBurnFast
expr: |
slo:http_availability:burn_rate_1h > 14.4
and
slo:http_availability:burn_rate_5m > 14.4
for: 2m
labels:
severity: critical
annotations:
summary: "Fast error budget burn detected"
description: "Error budget burning at {{ $value }}x rate"
# Slow burn: 6x rate, 6 hour window
# Approximately 5.36% of a 28-day budget in 6 hours at constant traffic
- alert: SLOErrorBudgetBurnSlow
expr: |
slo:http_availability:burn_rate_6h > 6
and
slo:http_availability:burn_rate_30m > 6
for: 15m
labels:
severity: warning
annotations:
summary: "Slow error budget burn detected"
description: "Error budget burning at {{ $value }}x rate"
# Error budget exhausted
- alert: SLOErrorBudgetExhausted
expr: slo:http_availability:error_budget_remaining < 0
for: 5m
labels:
severity: critical
annotations:
summary: "SLO error budget exhausted"
description: "Error budget remaining: {{ $value }}%"
SLO 仪表板
Grafana 仪表板结构:
┌────────────────────────────────────┐
│ SLO Compliance (Current) │
│ ✓ 99.95% (Target: 99.9%) │
├────────────────────────────────────┤
│ Error Budget Remaining: 65% │
│ ████████░░ 65% │
├────────────────────────────────────┤
│ SLI Trend (28 days) │
│ [Time series graph] │
├────────────────────────────────────┤
│ Burn Rate Analysis │
│ [Burn rate by time window] │
└────────────────────────────────────┘
查询示例:
# Current SLO compliance
sli:http_availability:ratio * 100
# Error budget remaining
slo:http_availability:error_budget_remaining
# Days until error budget exhausted (at current burn rate)
(slo:http_availability:error_budget_remaining / 100) * 28
/
slo:http_availability:burn_rate_5m
多窗口消耗率告警
# Combination of short and long windows reduces false positives
rules:
- alert: SLOBurnRateHigh
expr: |
(
slo:http_availability:burn_rate_1h > 14.4
and
slo:http_availability:burn_rate_5m > 14.4
)
or
(
slo:http_availability:burn_rate_6h > 6
and
slo:http_availability:burn_rate_30m > 6
)
labels:
severity: critical
SLO 审查流程
每周审查
- 当前 SLO 合规性
- 错误预算状态
- 趋势分析
- 事件影响
每月审查
- SLO 达成情况
- 错误预算使用情况
- 事件复盘
- SLO 调整
每季度审查
- SLO 相关性
- 目标调整
- 流程改进
- 工具增强
最佳实践
- 从面向用户的服务开始
- 使用多个 SLI(可用性、延迟等)
- 设定可实现的 SLO(不要以 100% 为目标)
- 实施多窗口告警以减少噪声
- 持续跟踪错误预算
- 定期审查 SLO
- 记录 SLO 决策
- 与业务目标保持一致
- 自动化 SLO 报告
- 使用 SLO 进行优先级排序
参考文件
- 内联示例 - SLO 定义模板
references/slo-definitions.md- SLO 定义模式references/error-budget.md- 错误预算计算
相关技能
prometheus-configuration- 用于指标采集grafana-dashboards- 用于 SLO 可视化
限制
- 仅当任务明确符合上述范围时,才使用此技能。
- 不要将输出视为特定环境验证、测试或专家评审的替代品。
- 如果缺少必需的输入、权限、安全边界或成功标准,请停止并请求澄清。
评论
支持 Markdown