首页/云/可观测性速查/均值和分位数:延迟观测的正确姿势
监控体系与方法40 条

均值和分位数:延迟观测的正确姿势

平均延迟会被长尾掩盖:99 个快请求加 1 个超慢请求,均值依然好看。延迟观测应使用 P50/P95/P99 分位并明确统计窗口,同时可统计超阈值请求占比。

可观测性速查云更新于 2026-10-12
P50一半请求快于该值,代表普遍体验
P95/P99尾部体验,更贴近用户投诉对应的信号
注意分位数不能跨实例直接平均,先聚合桶再计算

P50/P95/P99 与超时占比

P50/P95/P99 与超时占比
histogram_quantile(0.50, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))
histogram_quantile(0.95, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))
histogram_quantile(0.99, sum by (le) (rate(http_request_duration_seconds_bucket[5m])))

# 超过 1 秒的请求占比(桶相减,注意 +Inf 桶)
(sum(rate(http_request_duration_seconds_bucket{le="+Inf"}[5m]))
 - sum(rate(http_request_duration_seconds_bucket{le="1.0"}[5m])))
 / sum(rate(http_request_duration_seconds_bucket{le="+Inf"}[5m]))
分位值适合看趋势与 SLO,桶相减得到的超时占比更适合直接做阈值告警。

易错点

  • 把各实例的 P99 求平均得到的不是整体 P99,必须基于桶聚合计算
  • 分位窗口过长(如 24 小时)会把历史峰值与现状混在一起,告警应使用较短窗口

数据来源与参考

  • Prometheus 文档 · histogram_quantile()
  • Google SRE Book 第 6 章(分位数意义)
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌