*: register metrics handler for grpcproxy self

This commit is contained in:
tangcong 2020-07-02 22:55:18 +08:00
parent e94dc39edc
commit fff5d3cc03
3 changed files with 11 additions and 2 deletions

View File

@ -215,6 +215,7 @@ func startGRPCProxy(cmd *cobra.Command, args []string) {
mux := http.NewServeMux() mux := http.NewServeMux()
grpcproxy.HandleMetrics(mux, httpClient, client.Endpoints()) grpcproxy.HandleMetrics(mux, httpClient, client.Endpoints())
grpcproxy.HandleHealth(lg, mux, client) grpcproxy.HandleHealth(lg, mux, client)
grpcproxy.HandleProxyMetrics(mux)
lg.Info("gRPC proxy server metrics URL serving") lg.Info("gRPC proxy server metrics URL serving")
herr := http.Serve(mhttpl, mux) herr := http.Serve(mhttpl, mux)
if herr != nil { if herr != nil {
@ -407,6 +408,7 @@ func mustHTTPListener(lg *zap.Logger, m cmux.CMux, tlsinfo *transport.TLSInfo, c
httpmux.HandleFunc("/", http.NotFound) httpmux.HandleFunc("/", http.NotFound)
grpcproxy.HandleMetrics(httpmux, httpClient, c.Endpoints()) grpcproxy.HandleMetrics(httpmux, httpClient, c.Endpoints())
grpcproxy.HandleHealth(lg, httpmux, c) grpcproxy.HandleHealth(lg, httpmux, c)
grpcproxy.HandleProxyMetrics(httpmux)
if grpcProxyEnablePprof { if grpcProxyEnablePprof {
for p, h := range debugutil.PProfHandlers() { for p, h := range debugutil.PProfHandlers() {
httpmux.Handle(p, h) httpmux.Handle(p, h)

View File

@ -29,8 +29,9 @@ import (
) )
const ( const (
PathMetrics = "/metrics" PathMetrics = "/metrics"
PathHealth = "/health" PathHealth = "/health"
PathProxyMetrics = "/proxy/metrics"
) )
// HandleMetricsHealth registers metrics and health handlers. // HandleMetricsHealth registers metrics and health handlers.

View File

@ -23,6 +23,7 @@ import (
"time" "time"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.etcd.io/etcd/v3/etcdserver/api/etcdhttp" "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 { func shuffleEndpoints(r *rand.Rand, eps []string) []string {
// copied from Go 1.9<= rand.Rand.Perm // copied from Go 1.9<= rand.Rand.Perm
n := len(eps) n := len(eps)