Envoy HTTP 流量层面的 Metric 指标分析

1. 概述

Envoy 提供了丰富的指标系统,用于监控 HTTP 流量的各个方面。这些指标涵盖了 Downstream(入站)、Upstream(出站)、HTTP 过滤器和网络相关的统计信息。通过这些指标,可以深入了解流量模式、性能瓶颈和潜在问题,是实现精细化运维和保障服务稳定性的基础。

HTTP 流量指标,覆盖从客户端连接到后端服务的全链路。通过系统性地采集和分析这些指标,运维和开发团队能够:

  1. 快速定位瓶颈:利用延迟和吞吐量指标,精准定位性能短板。

  2. 有效管理容量:监控活跃连接、待处理队列和断路器状态,实现弹性容量规划。

  3. 提升系统韧性:通过健康检查和异常检测指标,自动化地隔离故障节点。

  4. 保障服务 SLO:基于错误率、延迟等黄金指标,建立准确的告警体系,确保服务质量。

深入理解并合理利用这些指标,是构建高可靠、高可观测性云原生服务网格的关键一步

  1. 指标分类架构

Envoy HTTP 指标整体可分为以下几大类:

  • Downstream(入站)指标:描述 Envoy 实例接收来自下游(客户端)请求的相关统计。

  • Upstream(出站)指标:描述 Envoy 实例向上游(后端服务)发送请求的相关统计。

  • Filter(过滤器)指标:特定 HTTP 过滤器(如路由、限流、压缩)产生的统计。

  • Network(网络)指标:与协议、流量控制、安全等底层网络相关的统计。

  • 其他系统指标:包括电路断路器、健康检查、负载均衡等高级功能指标。

3. Downstream(入站)指标

Downstream 指标用于监控 Envoy 接收客户端请求的整个生命周期。

3.1 连接统计指标

指标名称 类型 描述
http.downstream_cx_total Counter 下游连接总数
http.downstream_cx_ssl_total Counter 下游 TLS 连接总数
http.downstream_cx_http1_total Counter 下游 HTTP/1.1 连接总数
http.downstream_cx_http2_total Counter 下游 HTTP/2 连接总数
http.downstream_cx_http3_total Counter 下游 HTTP/3 连接总数
http.downstream_cx_active Gauge 当前活跃的下游连接数
http.downstream_cx_destroy Counter 已销毁的下游连接总数
http.downstream_cx_idle_timeout Counter 因空闲超时而关闭的连接数
http.downstream_cx_protocol_error Counter 下游协议错误总数
http.downstream_cx_length_ms Histogram 下游连接持续时间的分布(毫秒)

3.2 请求统计指标

指标名称 类型 描述
http.downstream_rq_total Counter 下游请求总数
http.downstream_rq_active Gauge 当前活跃的下游请求数
http.downstream_rq_1xx/2xx/3xx/4xx/5xx Counter 按 HTTP 状态码分类的响应计数
http.downstream_rq_time Histogram 下游请求总处理时间的分布(毫秒)
http.downstream_rq_timeout Counter 下游请求超时总数
http.downstream_rq_rx_reset Counter 接收到的下游请求重置总数
http.downstream_rq_too_large Counter 因请求体过大返回 413 错误的请求数

3.3 字节传输指标

指标名称 类型 描述
http.downstream_cx_rx_bytes_total Counter 从下游接收的字节总数
http.downstream_cx_tx_bytes_total Counter 向下游发送的字节总数
http.downstream_cx_rx_bytes_buffered Gauge 当前缓冲区中从下游接收的字节数
http.downstream_cx_tx_bytes_buffered Gauge 当前缓冲区中准备向下游发送的字节数

4. Upstream(出站)指标

Upstream 指标用于监控 Envoy 向后端集群转发请求的行为。

4.1 连接和连接池指标

指标名称 类型 描述
cluster.<name>.upstream_cx_total Counter 向上游建立的总连接数
cluster.<name>.upstream_cx_active Gauge 当前活跃的上游连接数
cluster.<name>.upstream_cx_connect_fail Counter 连接上游失败的总数
cluster.<name>.upstream_cx_connect_timeout Counter 连接上游超时的总数
cluster.<name>.upstream_cx_connect_ms Histogram 向上游建立连接所耗时间的分布(毫秒)
cluster.<name>.upstream_cx_pool_overflow Counter 因连接池耗尽而拒绝的连接请求数
cluster.<name>.upstream_rq_pending_overflow Counter 因待处理队列溢出而拒绝的请求数

4.2 请求和响应指标

指标名称 类型 描述
cluster.<name>.upstream_rq_total Counter 向上游转发的总请求数
cluster.<name>.upstream_rq_active Gauge 当前发往上游的活跃请求数
cluster.<name>.upstream_rq_2xx/3xx/4xx/5xx Counter 从上游接收的按状态码分类的响应计数
cluster.<name>.upstream_rq_time Histogram 上游请求处理时间的分布(毫秒)
cluster.<name>.upstream_rq_timeout Counter 向上游请求超时的总数
cluster.<name>.upstream_rq_retry Counter 请求重试的总次数

4.3 网络异常指标

指标名称 类型 描述
cluster.<name>.upstream_cx_reset Counter 上游连接重置的总数
cluster.<name>.upstream_cx_read_timeout Counter 从上游读取数据超时的总数
cluster.<name>.upstream_rq_connection_reset Counter 因连接重置导致的请求失败数
cluster.<name>.upstream_rq_network_failure Counter 因网络故障导致的请求失败数

5. HTTP 过滤器指标

5.1 路由过滤器指标

指标名称 类型 描述
http.no_route Counter 请求未匹配到任何路由(导致 404)的次数
http.no_cluster Counter 路由指向了一个不存在的集群(导致 503)的次数
http.rq_redirect Counter 触发重定向的请求数
http.rq_direct_response Counter 直接返回响应的请求数(未转发至上游)

5.2 限流过滤器指标

指标名称 类型 描述
http.rate_limit.enabled Counter 限流过滤器被启用的请求数
http.rate_limit.denied Counter 被限流策略拒绝的请求数

5.3 压缩过滤器指标

指标名称 类型 描述
http.compression.bytes_in Counter 压缩前响应体的字节总数
http.compression.bytes_out Counter 压缩后响应体的字节总数
http.compression.uncompressed_bytes_out Counter 未进行压缩的响应体字节总数

6. 网络与协议指标

6.1 流量控制指标

指标名称 类型 描述
http.downstream_flow_control_paused_reading_total Counter 下游因流量控制而暂停读取的总次数
cluster.<name>.upstream_flow_control_paused_reading_total Counter 上游因流量控制而暂停读取的总次数

6.2 HTTP/2 协议指标

指标名称 类型 描述
http2.rx_reset Counter 接收到的 HTTP/2 RST_STREAM 帧总数
http2.tx_reset Counter 发送的 HTTP/2 RST_STREAM 帧总数
http2.streams_active Gauge 当前活跃的 HTTP/2 流数量
http2.keepalive_timeout Counter HTTP/2 PING 帧超时导致的连接关闭次数

7. 高级功能指标

7.1 电路断路器指标

指标名称 类型 描述
cluster.<name>.circuit_breakers.<priority>.rq_open Gauge 请求断路器当前是否打开(1)或关闭(0)
cluster.<name>.circuit_breakers.<priority>.cx_open Gauge 连接断路器当前是否打开(1)或关闭(0)
cluster.<name>.circuit_breakers.<priority>.remaining_rq Gauge 请求断路器剩余的许可数(需配置开启)

7.2 健康检查与异常检测指标

指标名称 类型 描述
cluster.<name>.health_check.healthy Gauge 当前被健康检查视为健康的上游主机数
cluster.<name>.health_check.failure Counter 主动健康检查失败的累计次数
cluster.<name>.outlier_detection.ejections_enforced_total Counter 因异常检测而强制驱逐主机的总次数
cluster.<name>.outlier_detection.ejections_active Gauge 当前处于被驱逐状态的主机数量

7.3 负载均衡指标

指标名称 类型 描述
cluster.<name>.lb_healthy_panic Counter 触发"恐慌"模式(将流量发送至不健康主机)的次数
cluster.<name>.lb_zone_routing_cross_zone Counter 流量被路由到其他可用区的次数

8. 指标使用最佳实践

8.1 核心监控与告警策略

监控维度 推荐指标 告警建议
流量与错误率 rate(http.downstream_rq_total[1m]) rate(http.downstream_rq_5xx[1m]) 5xx 错误率超过 1%(或业务可容忍阈值)
延迟 histogram_quantile(0.99, sum(rate(http.downstream_rq_time_bucket[1m])) by (le)) P99 延迟超过 500ms(根据业务调整)
上游健康状态 cluster.<name>.health_check.healthy rate(cluster.<name>.upstream_cx_connect_fail[1m]) 健康主机数低于最小值,或连接失败率突增
资源耗尽风险 cluster.<name>.circuit_breakers.<priority>.rq_open cluster.<name>.upstream_rq_pending_overflow 断路器打开(值为1),或待处理队列溢出
连接稳定性 rate(http.downstream_cx_protocol_error[1m]) rate(cluster.<name>.upstream_cx_reset[1m]) 协议错误或连接重置速率异常升高

8.2 可观测性集成建议

  • Prometheus :使用 Envoy 的 /stats/prometheus 端点暴露指标,配置 scrape_configs 进行采集。

  • Grafana:导入官方或社区提供的 Envoy 仪表盘模板(ID: 12480),快速实现可视化。

  • 日志与追踪:指标与访问日志、分布式追踪(如 Zipkin, Jaeger)结合,形成完整的可观测性体系。

8.3 性能调优参考

  • 高延迟 :关注 upstream_rq_timedownstream_rq_time 的差异,定位瓶颈在上游服务还是 Envoy 自身。

  • 连接建立慢 :分析 upstream_cx_connect_ms 的分布,优化网络或调整 connect_timeout 设置。

  • 内存/连接异常 :监控 active 系列 Gauge 指标,排查连接泄漏或请求堆积问题。

相关推荐
上海云盾-小余1 小时前
海外恶意 UDP 攻击溯源:分层封禁策略与业务兼容平衡方案
网络·网络协议·udp
智慧光迅AINOPOL1 小时前
校园全光网建设指南:从架构到调优,打造稳定高体验校园网络
网络·全光网解决方案·全光网·酒店全光解决方案·泛住宿全光网解决方案
被摘下的星星2 小时前
Internet 的域名系统:从“名字”到“地址”的翻译官
网络
TimeAground3 小时前
HTTP 协议全解:从报文到 HTTP/3,Android 开发者需要知道的一切
http
Diros1g3 小时前
如何通过普通网线给另一个设备供网
网络·网络协议
lifewange3 小时前
如何设计一个 RESTful API
后端·http·restful
beyond阿亮4 小时前
IEC104 Client Simulator - IEC104 主站/客户端模拟器 仿真器免费使用教程
运维·服务器·网络
(Charon)4 小时前
【C++/Qt】Qt 封装 TCP 客户端底层 Network 类:连接、收发、自动测试与错误处理
服务器·网络·qt·tcp/ip