在 AlertManager 中配置一条规则:某服务异常率连续 3 分钟 >5% 即告警
解读
国内生产环境对 Dubbo 服务的可用性要求极高,面试官通过“异常率>5% 连续 3 分钟”这一可量化、可验证的指标,考察候选人能否把 Dubbo 的监控数据(QPS、RT、异常次数)与 Prometheus+AlertManager 的语法、语义、运维规范打通。
关键点:
- 异常率 = 异常次数 / 总调用次数,必须基于 Dubbo 暴露的 Prometheus 指标做计算;
- 连续 3 分钟 要用 Prometheus 的
for: 3m,不能用 AlertManager 的group_wait/group_interval混淆; - 规则必须带集群、应用、接口、方法四级标签,防止误告;
- 需给出恢复阈值与摘要模板,体现可观测闭环思维。
知识点
- Dubbo 3.x 自带 dubbo_consumer_requests_total、dubbo_consumer_requests_error_total 两个 Counter,维度包含 {application, interface, method, version, group, ip};
- Prometheus 计算率值必须用 rate() 或 increase(),避免原始 Counter 绝对值抖动;
- 告警规则文件统一放在 /etc/prometheus/rules/dubbo_alerts.yml,通过
prometheus --rule.file热加载; - 国内金融场景要求告警级别=warning、值班路由=钉钉+飞书,需在 AlertManager 的 route 里配置
match: severity = warning; - 必须配套 SLO 燃烧率思路:5% 异常率对应 30 天可用性 99.95%,面试时主动提及可加分。
答案
- Prometheus 侧规则(dubbo_alerts.yml)
groups:
- name: dubbo_consumer_error_rate
rules:
- alert: DubboConsumerErrorRateHigh
expr: |
(
sum by (application, interface, method, ip) (
rate(dubbo_consumer_requests_error_total[1m])
)
/
sum by (application, interface, method, ip) (
rate(dubbo_consumer_requests_total[1m])
)
) > 0.05
for: 3m
labels:
severity: warning
team: middleware
product: dubbo
annotations:
summary: "Dubbo接口异常率超过5%"
description: "应用 {{ $labels.application }} 接口 {{ $labels.interface }}#{{ $labels.method }} 在 {{ $labels.ip }} 异常率 {{ $value | humanizePercentage }},持续3分钟"
- AlertManager 侧路由(alertmanager.yml 片段)
route:
group_by: [application, interface, severity]
group_wait: 30s
group_interval: 2m
repeat_interval: 4h
receiver: team-dingtalk
routes:
- match:
severity: warning
product: dubbo
receiver: team-dingtalk
continue: true
receivers:
- name: team-dingtalk
webhook_configs:
- url: 'http://inhouse-dingtalk-webhook/dubbo'
send_resolved: true
- 验证步骤
curl -XPOST http://prometheus:9090/-/reload热加载规则;- 使用
vector(1)伪造 dubbo_consumer_requests_error_total 瞬时增长,确认 Prometheus Expression 返回 >0.05; - 观察 AlertManager UI 状态由 Pending → Firing,钉钉群收到卡片消息即算通过。
拓展思考
- 多集群场景:通过 external_labels 中的
cluster=hz01区分,避免杭州与深圳数据混算; - 慢调用污染:异常率只捕捉 Exception,若要把 >3s 的超时也算“业务异常”,可自定义 Dubbo Filter 把超时次数记录到 dubbo_consumer_requests_timeout_total,再与 error_total 相加;
- 自动恢复:在 Annotation 里带上 dubbo qos 端口 “telnet ip 22222 → offline” 指令,值班同学可一键下线问题节点;
- 灰度发布:利用 dubbo_attachment 的 gray=true 标签,给灰度流量单独建一条 error_rate 规则,灰度异常率>1% 就立即熔断,保护基线环境;
- 面试加分项:主动画出告警闭环——Prometheus 发现、AlertManager 分发、钉钉触达、On-Call 处理、Arthas 诊断、规则回写,展示全链路可观测能力。