*: register metrics handler for grpcproxy self

release-3.5
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()
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)

View File

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

View File

@ -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)