Skip to content
cccskills
FreePublished on GitHub

monitoring-alerting

配置监控和告警时使用。适用于 Prometheus / Grafana / Loki / PagerDuty / SLO 定义 / 告警规则设计。融合 Google SRE 四大黄金信号 + USE Method + 告警分级。

The English summary is being prepared. Showing the original description.

Run score Not tested

See how to install

Files included (3)

  • SKILL.md7.8 KB
  • templates/alert-rule-template.md954 B
  • templates/monitoring-setup-template.md1.1 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

监控与告警(Monitoring & Alerting)

参考来源:Google《Site Reliability Engineering》、Brendan Gregg USE Method、Prometheus 官方、Grafana Labs、PagerDuty Incident Response。

适用场景

  • 监控系统搭建(Prometheus + Grafana)
  • 日志收集(Loki / ELK)
  • 告警规则设计
  • SLO / SLI 定义
  • 仪表盘设计
  • On-call 配置

核心原则

1. 四大黄金信号(Google SRE)
   Latency / Traffic / Errors / Saturation

2. USE Method(Brendan Gregg)
   每种资源:Utilization / Saturation / Errors

3. 告警基于 SLO,不基于阈值
   "错误预算消耗 > 50%" 比 "CPU > 80%" 有意义

4. 告警可操作
   收到告警 → 知道做什么
   不可操作的告警 = 噪音

5. 分级告警
   P1(立即)/ P2(1 小时)/ P3(工作时间)/ P4(下周)

6. 不 alert fatigue
   宁可少告警,不可多到忽略

监控栈选型

组件开源SaaS
指标Prometheus + GrafanaDatadog / New Relic
日志Loki / ELKDatadog Logs / Splunk
追踪Jaeger / TempoDatadog APM / Honeycomb
告警AlertmanagerPagerDuty / OpsGenie
UptimeBlackbox ExporterUptimeRobot / Better Stack
错误Sentry(自建)Sentry Cloud
APMOpenTelemetryDatadog / Dynatrace

四大黄金信号

# Prometheus 规则示例

# 1. Latency(延迟)
- record: http_request_duration_seconds:p99
  expr: histogram_quantile(0.99, rate(http_request_duration_seconds_bucket[5m]))

# 2. Traffic(流量)
- record: http_requests_per_second
  expr: rate(http_requests_total[5m])

# 3. Errors(错误率)
- record: http_error_rate
  expr: rate(http_requests_total{status=~"5.."}[5m]) / rate(http_requests_total[5m])

# 4. Saturation(饱和度)
- record: cpu_saturation
  expr: 1 - avg(rate(node_cpu_seconds_total{mode="idle"}[5m]))

SLO / SLI 定义

SLI(Service Level Indicator):
  - 可用性:成功请求 / 总请求
  - 延迟:P99 < 500ms 的请求比例
  - 吞吐:每秒处理请求数

SLO(Service Level Objective):
  - 可用性 SLO:99.9%(每月允许 43 分钟不可用)
  - 延迟 SLO:99% 请求 P99 < 500ms
  - 错误 SLO:错误率 < 0.1%

错误预算(Error Budget):
  - 月预算 = 1 - SLO = 0.1% = 43 分钟
  - 消耗 > 50% → 冻结发布
  - 消耗 > 80% → 专注稳定性
# Prometheus SLO 告警(Burn Rate)
groups:
  - name: slo-alerts
    rules:
      # 1 小时 burn rate > 14.4(快速消耗)→ P1
      - alert: HighErrorBudgetBurn_1h
        expr: |
          (
            rate(http_requests_total{status=~"5.."}[1h])
            / rate(http_requests_total[1h])
          ) > 14.4 * 0.001
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "Error budget burning fast (1h window)"
      
      # 6 小时 burn rate > 6 → P2
      - alert: HighErrorBudgetBurn_6h
        expr: |
          (
            rate(http_requests_total{status=~"5.."}[6h])
            / rate(http_requests_total[6h])
          ) > 6 * 0.001
        for: 5m
        labels:
          severity: warning

告警规则设计

分级

级别含义响应时间通知方式
P1 Critical服务不可用 / 数据丢失立即电话 + Slack
P2 High功能降级 / 性能退化1 小时Slack + 邮件
P3 Medium非紧急但需关注工作时间Slack
P4 Low信息性下周邮件

好告警 vs 坏告警

好告警:
  ✅ "订单创建错误率 > 5% 持续 2 分钟"
  ✅ "错误预算消耗 > 50%"
  ✅ "数据库连接池使用 > 90%"

坏告警:
  ❌ "CPU > 80%"(可能正常)
  ❌ "磁盘 > 70%"(太早)
  ❌ "某个 Pod 重启了"(可能正常)
  ❌ "日志有 ERROR"(太多噪音)

告警模板

- alert: HighErrorRate
  expr: http_error_rate > 0.05
  for: 2m
  labels:
    severity: critical
    team: backend
  annotations:
    summary: "High error rate: {{ $value | humanizePercentage }}"
    description: "Error rate > 5% for 2 minutes"
    runbook: "https://wiki.example.com/runbooks/high-error-rate"
    dashboard: "https://grafana.example.com/d/xxx"

Grafana 仪表盘设计

推荐 5 个 Dashboard

1. 服务总览(Golden Signals)
   - QPS / 错误率 / P50 / P99 / 饱和度
   - 按服务分组

2. 业务指标
   - 订单数 / 支付成功率 / 注册数
   - 按时间对比(vs 昨天 / 上周)

3. 基础设施
   - CPU / Memory / Disk / Network
   - 按节点 / Pod 分组

4. 数据库
   - 连接数 / 慢查询 / 锁等待 / 复制延迟

5. 发布追踪
   - 部署时间线
   - 发布前后指标对比

Prometheus + Grafana 部署

# docker-compose(快速启动)
services:
  prometheus:
    image: prom/prometheus:latest
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    ports:
      - "9090:9090"

  grafana:
    image: grafana/grafana:latest
    ports:
      - "3000:3000"
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=admin

  alertmanager:
    image: prom/alertmanager:latest
    volumes:
      - ./alertmanager.yml:/etc/alertmanager/alertmanager.yml
    ports:
      - "9093:9093"
# prometheus.yml
global:
  scrape_interval: 15s
  evaluation_interval: 15s

rule_files:
  - "alerts/*.yml"

alerting:
  alertmanagers:
    - static_configs:
        - targets: ['alertmanager:9093']

scrape_configs:
  - job_name: 'app'
    static_configs:
      - targets: ['app:8080']
    metrics_path: '/metrics'

日志收集(Loki)

# Loki + Promtail
services:
  loki:
    image: grafana/loki:latest
    ports:
      - "3100:3100"

  promtail:
    image: grafana/promtail:latest
    volumes:
      - /var/log:/var/log
      - ./promtail.yml:/etc/promtail/config.yml
日志规范:
  - JSON 格式(结构化)
  - 含 trace_id / service / level / timestamp
  - 不输出 PII / Token
  - 保留期:7~30 天

On-call 配置

轮值:
  - 每周轮换
  - 主 + 副(backup)
  - 交接文档

升级路径:
  P1:5 分钟无响应 → 升级到副
  P1:15 分钟无响应 → 升级到 Tech Lead
  P1:30 分钟无响应 → 升级到 CTO

工具:
  - PagerDuty / OpsGenie / Grafana OnCall
  - Slack 集成
  - 电话 + 短信

配套模板

  • templates/monitoring-setup-template.md — 监控配置 + SLO + 告警规则 + 仪表盘
  • templates/alert-rule-template.md — 告警规则与发布门禁

质量自检

□ 四大黄金信号覆盖
□ SLO / SLI 定义
□ 告警基于 SLO(不基于阈值)
□ 告警分级(P1~P4)
□ 告警可操作(有 Runbook)
□ 不 alert fatigue
□ 仪表盘覆盖(5 个)
□ 日志结构化 + 集中
□ On-call 配置
□ 升级路径
□ 错误预算跟踪
□ 发布后监控

常见坑

  1. CPU > 80% 告警——可能正常,应该看 SLO
  2. 告警太多——alert fatigue,重要的被忽略
  3. 告警不可操作——收到不知道做什么
  4. 不分级——所有告警都是 P1
  5. 没有 Runbook——半夜被叫起来不知道怎么修
  6. 日志不结构化——搜索困难
  7. 不监控业务指标——只盯技术指标
  8. SLO 不定义——不知道什么算"正常"
  9. 不做错误预算——永远在救火
  10. On-call 不轮换——一个人扛

与其他 skill 的协作

上游:
  ci-cd-pipeline → 部署后触发监控
  release-strategy → 发布后观察
  kubernetes-orchestration → K8s 指标

下游:
  sre-operations 工作流 → 事故响应
  backend-engineer observability → 应用层指标

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

A/B 测试设计与分析时使用。适用于产品实验、功能验证、转化率优化。融合假设驱动 + 样本量计算 + 置信度判断。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow53Updated May 19, 2026

上线前业务方/产品方验收时使用。适用于功能交付确认、UAT、发布会签。融合 BDD Given-When-Then、Specification by Example、ATDD。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow53Updated May 19, 2026

设计无障碍可访问的界面时使用。适用于满足 WCAG 标准、键盘导航、屏幕阅读器支持。优先使用 WCAG 2.2 AA 级标准 + 键盘 + 焦点 + 对比度 + ARIA。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow53Updated May 19, 2026

实现可访问性(无障碍)时使用。覆盖 WCAG 2.2 AA / ARIA / 键盘导航 / 屏幕阅读器 / 颜色对比 / 焦点管理。融合 React Aria / Radix UI / Headless UI 实践 + axe-core 自动化测试。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow53Updated May 19, 2026

AI 模型部署时使用。适用于推理服务 / GPU / TensorRT / 监控 / 扩缩容。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow53Updated May 19, 2026

数据分析报告输出时使用。适用于业务分析报告、周报、专项分析、决策支持。融合洞察 + 建议 + 行动项。

The English summary is being prepared. Showing the original description.

zhaoxuya520/AI-Fullstack-Delivery-Workflow53Updated May 19, 2026

See all skills by zhaoxuya520

Report a problem with this skill