如何通过Prometheus基于带客户ID的URI监控Istio请求统计?
基于Prometheus-Grafana监控Istio入口网关的客户请求量
1. 配置Istio遥测,提取URL中的客户ID标签
Istio默认请求指标不会自动解析URL里的客户ID,需要通过Telemetry资源扩展指标维度,从请求路径中提取客户ID并添加为标签。
创建如下YAML配置(适配Istio 1.15.4):
apiVersion: telemetry.istio.io/v1alpha1 kind: Telemetry metadata: name: gateway-telemetry namespace: istio-system spec: selector: matchLabels: istio: ingressgateway # 匹配你的入口网关标签 metrics: - providers: - name: prometheus overrides: - match: metric: istio_requests_total dimensions: customer_id: "request.path | regex('^/api/v1/customer_(\\d+)$', '$1')" - match: metric: istio_request_duration_milliseconds dimensions: customer_id: "request.path | regex('^/api/v1/customer_(\\d+)$', '$1')"
执行命令应用配置:
kubectl apply -f gateway-telemetry.yaml -n istio-system
2. 验证Prometheus采集的指标
配置生效后,在Prometheus中执行以下查询,确认istio_requests_total指标已包含customer_id标签:
istio_requests_total{customer_id=~"customer_11|customer_12"}
返回对应标签的时间序列即说明配置生效。
3. 在Grafana中创建监控面板
统计客户累计请求数
添加面板,使用如下PromQL查询:
sum(istio_requests_total{customer_id="customer_11"})
复制面板并修改查询中的客户ID为customer_12,即可分别展示两个客户的累计请求数。
统计客户请求增量(按时间窗口)
若需查看一段时间内的请求变化趋势,使用增量查询:
sum(increase(istio_requests_total{customer_id="customer_11"}[5m]))
调整[5m]为所需时间窗口(如[1m]、[1h]),并将图表类型设置为折线图,即可展示请求量的动态变化。
内容的提问来源于stack exchange,提问作者Neelesh Gurjar
相关产品推荐
相关产品推荐

