executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
configure-alerting-rulesConfigure Prometheus Alertmanager with routing trees, receivers (Slack, PagerDuty, email), inhibition rules, silences, and notification templates for actionable incident alerting. Use when implementing proactive monitoring with automated incident detection, routing alerts to the appropriate team by severity, reducing alert fatigue through grouping and dedup…
Independent GitHub snapshot · Automated classification · Original documentation governs
設 Prometheus 告警規則與 Alertmanager 以得可靠可行之事件通知。
見 Extended Examples 取完整配置檔與模板。
裝並配 Alertmanager 以接收自 Prometheus 之告警。
Docker Compose 部署(基本結構):
version: '3.8'
services:
alertmanager:
image: prom/alertmanager:v0.26.0
ports:
- "9093:9093"
volumes:
- ./alertmanager.yml:/etc/alertmanager/alertmanager.yml
# ... (see EXAMPLES.md for complete configuration)
基本 Alertmanager 配置(alertmanager.yml 摘):
global:
resolve_timeout: 5m
slack_api_url: 'https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK'
route:
receiver: 'default-receiver'
group_by: ['alertname', 'cluster', 'service']
group_wait: 30s
group_interval: 5m
repeat_interval: 4h
routes:
- match:
severity: critical
receiver: pagerduty-critical
# ... (see EXAMPLES.md for complete routing, inhibition rules, and receivers)
配 Prometheus 用 Alertmanager(prometheus.yml):
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093
timeout: 10s
api_version: v2
預期: Alertmanager UI 於 http://localhost:9093 可達;Prometheus「Status > Alertmanagers」顯示 UP。
失敗時:
docker logs alertmanagercurl http://alertmanager:9093/api/v2/statuscurl -X POST <SLACK_WEBHOOK_URL> -d '{"text":"test"}'amtool check-config alertmanager.yml作條件滿足時觸之告警規則。
建告警規則檔(/etc/prometheus/rules/alerts.yml 摘):
groups:
- name: instance_alerts
interval: 30s
rules:
- alert: InstanceDown
expr: up == 0
for: 5m
labels:
severity: critical
team: infrastructure
annotations:
summary: "Instance {{ $labels.instance }} is down"
description: "{{ $labels.instance }} has been down for >5min."
runbook_url: "https://wiki.example.com/runbooks/instance-down"
- alert: HighCPUUsage
expr: 100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100) > 80
for: 10m
labels:
severity: warning
annotations:
summary: "High CPU usage on {{ $labels.instance }}"
# ... (see EXAMPLES.md for complete alerts)
告警設計良實踐:
for 時長:防抖動告警。多數告警用 5-10 分鐘載規則入 Prometheus:
# prometheus.yml
rule_files:
- "rules/*.yml"
驗並重載:
promtool check rules /etc/prometheus/rules/alerts.yml
curl -X POST http://localhost:9090/-/reload
預期: 告警見於 Prometheus「Alerts」頁;閾值超時告警觸;Alertmanager 收觸之告警。
失敗時:
promtool check rules 驗規則語法設可讀且可行之通知訊息。
建模板檔(/etc/alertmanager/templates/default.tmpl 摘):
{{ define "slack.default.title" }}
[{{ .Status | toUpper }}] {{ .GroupLabels.alertname }}
{{ end }}
{{ define "slack.default.text" }}
{{ range .Alerts }}
*Alert:* {{ .Labels.alertname }}
*Severity:* {{ .Labels.severity }}
*Summary:* {{ .Annotations.summary }}
{{ if .Annotations.runbook_url }}*Runbook:* {{ .Annotations.runbook_url }}{{ end }}
{{ end }}
{{ end }}
# ... (see EXAMPLES.md for complete email and PagerDuty templates)
於 receivers 用模板:
receivers:
- name: 'slack-custom'
slack_configs:
- channel: '#alerts'
title: '{{ template "slack.default.title" . }}'
text: '{{ template "slack.default.text" . }}'
預期: 通知格式一致、含所有相關脈絡、附 runbook 連結可行。
失敗時:
amtool template test --config.file=alertmanager.yml{{ . | json }} 以調試模板數據結構以智能路由規則優化告警遞送。
進階路由配置(摘):
route:
receiver: 'default-receiver'
group_by: ['alertname', 'cluster', 'service']
group_wait: 30s
routes:
- match:
team: platform
receiver: 'team-platform'
routes:
- match:
severity: critical
receiver: 'pagerduty-platform'
group_wait: 10s
repeat_interval: 15m
continue: true # Also send to Slack
# ... (see EXAMPLES.md for complete routing with time intervals)
分組策略:
# Group by alertname: All HighCPU alerts bundled together
group_by: ['alertname']
# Group by alertname AND cluster: Separate notifications per cluster
group_by: ['alertname', 'cluster']
預期: 告警路由至正確團隊、合邏輯分組、時序合嚴重度。
失敗時:
amtool config routes test --config.file=alertmanager.yml --alertname=HighCPU --label=severity=criticalamtool config routes show --config.file=alertmanager.ymlcontinue: true以抑制規則與暫時靜默減告警雜音。
抑制規則(抑從屬告警):
inhibit_rules:
# Cluster down suppresses all node alerts in that cluster
- source_match:
alertname: 'ClusterDown'
severity: 'critical'
target_match_re:
alertname: '(InstanceDown|HighCPU|HighMemory)'
equal: ['cluster']
# Service down suppresses latency and error alerts
- source_match:
alertname: 'ServiceDown'
target_match_re:
alertname: '(HighLatency|HighErrorRate)'
equal: ['service', 'namespace']
# ... (see EXAMPLES.md for more inhibition patterns)
程序式建靜默:
# Silence during maintenance
amtool silence add \
instance=app-server-1 \
--author="ops-team" \
--comment="Scheduled maintenance" \
--duration=2h
# List and manage silences
amtool silence query
amtool silence expire <SILENCE_ID>
預期: 抑制自動減連鎖告警;靜默於計畫維護中防通知。
失敗時:
連 Alertmanager 至 PagerDuty、Opsgenie、Jira 等。
PagerDuty 整合(摘):
receivers:
- name: 'pagerduty'
pagerduty_configs:
- routing_key: 'YOUR_INTEGRATION_KEY'
severity: '{{ .CommonLabels.severity }}'
description: '{{ range .Alerts.Firing }}{{ .Annotations.summary }}{{ end }}'
details:
firing: '{{ .Alerts.Firing | len }}'
alertname: '{{ .GroupLabels.alertname }}'
# ... (see EXAMPLES.md for complete integration examples)
自訂整合之 Webhook:
receivers:
- name: 'webhook-custom'
webhook_configs:
- url: 'https://your-webhook-endpoint.com/alerts'
send_resolved: true
預期: 告警於 PagerDuty 建事件、見於團隊通訊頻道、觸值班升呈。
失敗時:
--log.level=debugfor 時長:無 for 之告警於瞬峰觸。總用 5-10 分鐘窗['...'] 分組發個別通知。用具體標籤分組setup-prometheus-monitoring - 定供告警規則之指標與記錄規則define-slo-sli-sla - 生錯誤預算管理之 SLO 燒率告警write-incident-runbook - 建告警註中連結之 runbookbuild-grafana-dashboards - 視覺化告警觸發歷史與靜默模式