Skip to content

指标

metrics 块在普通 HTTP 上暴露 Prometheus 格式的计数器。与 gRPC StatsService 报告的同一批计数器,会出现在 /metrics(以及位于 /debug/pprof/ 的运行时调试端点)。

选项

字段类型默认值允许值描述
tagstring(required for routing)<inbound tag>metrics 入站的路由 tag。若想用规则路由 metrics 端点(通常都需要)则必填。
listenstring127.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" }
    ]
  }
}

说明

  • metricsstats 共享同一份计数器存储, 因此仍需要 stats: {} 以及 policy 中 相关计数器开关。
  • 端点同时提供 /metrics 上的 Prometheus 文本格式与 Go net/http/pprof handlers(/debug/pprof/)。监听地址请保持 只对 localhost 开放。

源码: infra/conf/metrics.go:8-11 · v26.6.1 (94ffd50)

由 Argsment 出品的 Core Tutorial