diff --git a/etcdmain/grpc_proxy.go b/etcdmain/grpc_proxy.go index 0e7665f3274..1bf7a8acf88 100644 --- a/etcdmain/grpc_proxy.go +++ b/etcdmain/grpc_proxy.go @@ -215,6 +215,7 @@ func startGRPCProxy(cmd *cobra.Command, args []string) { mux := http.NewServeMux() grpcproxy.HandleMetrics(mux, httpClient, client.Endpoints()) grpcproxy.HandleHealth(lg, mux, client) + grpcproxy.HandleProxyMetrics(mux) lg.Info("gRPC proxy server metrics URL serving") herr := http.Serve(mhttpl, mux) if herr != nil { @@ -407,6 +408,7 @@ func mustHTTPListener(lg *zap.Logger, m cmux.CMux, tlsinfo *transport.TLSInfo, c httpmux.HandleFunc("/", http.NotFound) grpcproxy.HandleMetrics(httpmux, httpClient, c.Endpoints()) grpcproxy.HandleHealth(lg, httpmux, c) + grpcproxy.HandleProxyMetrics(httpmux) if grpcProxyEnablePprof { for p, h := range debugutil.PProfHandlers() { httpmux.Handle(p, h) diff --git a/etcdserver/api/etcdhttp/metrics.go b/etcdserver/api/etcdhttp/metrics.go index b34a26dfe3a..9f3846cc5ac 100644 --- a/etcdserver/api/etcdhttp/metrics.go +++ b/etcdserver/api/etcdhttp/metrics.go @@ -29,8 +29,9 @@ import ( ) const ( - PathMetrics = "/metrics" - PathHealth = "/health" + PathMetrics = "/metrics" + PathHealth = "/health" + PathProxyMetrics = "/proxy/metrics" ) // HandleMetricsHealth registers metrics and health handlers. diff --git a/proxy/grpcproxy/metrics.go b/proxy/grpcproxy/metrics.go index 40e56ad5c56..ed2e62973eb 100644 --- a/proxy/grpcproxy/metrics.go +++ b/proxy/grpcproxy/metrics.go @@ -23,6 +23,7 @@ import ( "time" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" "go.etcd.io/etcd/v3/etcdserver/api/etcdhttp" ) @@ -98,6 +99,11 @@ func HandleMetrics(mux *http.ServeMux, c *http.Client, eps []string) { }) } +// HandleProxyMetrics registers metrics handler on '/proxy/metrics'. +func HandleProxyMetrics(mux *http.ServeMux) { + mux.Handle(etcdhttp.PathProxyMetrics, promhttp.Handler()) +} + func shuffleEndpoints(r *rand.Rand, eps []string) []string { // copied from Go 1.9<= rand.Rand.Perm n := len(eps)