指标
metrics 块在普通 HTTP 上暴露 Prometheus 格式的计数器。与 gRPC StatsService 报告的同一批计数器,会出现在 /metrics(以及位于 /debug/pprof/ 的运行时调试端点)。
选项
| 字段 | 类型 | 默认值 | 允许值 | 描述 |
|---|---|---|---|---|
tag | string | (required for routing) | <inbound tag> | metrics 入站的路由 tag。若想用规则路由 metrics 端点(通常都需要)则必填。 |
listen | string | 127.0.0.1:0 | <host:port> | metrics 端点的 HTTP 监听地址。为空时仅注册进程内入站。 |
源码: infra/conf/metrics.go:8-11 · 锚定版本 v26.6.1 (94ffd50)
示例
json
{
"stats": {},
"metrics": {
"tag": "metrics",
"listen": "127.0.0.1:9099"
},
"policy": {
"system": {
"statsInboundUplink": true,
"statsInboundDownlink": true,
"statsOutboundUplink": true,
"statsOutboundDownlink": true
}
},
"routing": {
"rules": [
{ "type": "field", "inboundTag": ["metrics"], "outboundTag": "metrics" }
]
}
}说明
metrics与stats共享同一份计数器存储, 因此仍需要stats: {}以及policy中 相关计数器开关。- 端点同时提供
/metrics上的 Prometheus 文本格式与 Gonet/http/pprofhandlers(/debug/pprof/)。监听地址请保持 只对 localhost 开放。
源码: infra/conf/metrics.go:8-11 · v26.6.1 (94ffd50)
