@@ -32,6 +32,7 @@ import (
32
32
33
33
"github.com/gorilla/websocket"
34
34
grpc_logrus "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus"
35
+ grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
35
36
grpcruntime "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
36
37
"github.com/improbable-eng/grpc-web/go/grpcweb"
37
38
"github.com/prometheus/common/route"
@@ -1107,6 +1108,15 @@ func startAPIEndpoint(ctx context.Context, cfg *Config, wg *sync.WaitGroup, serv
1107
1108
)
1108
1109
}
1109
1110
1111
+ grpcMetrics := grpc_prometheus .NewServerMetrics ()
1112
+ grpcMetrics .EnableHandlingTimeHistogram (
1113
+ grpc_prometheus .WithHistogramBuckets ([]float64 {.005 , .025 , .05 , .1 , .5 , 1 , 2.5 , 5 , 30 , 60 , 120 , 240 , 600 }),
1114
+ )
1115
+ opts = append (opts ,
1116
+ grpc .StreamInterceptor (grpcMetrics .StreamServerInterceptor ()),
1117
+ grpc .UnaryInterceptor (grpcMetrics .UnaryServerInterceptor ()),
1118
+ )
1119
+
1110
1120
m := cmux .New (l )
1111
1121
restMux := grpcruntime .NewServeMux ()
1112
1122
grpcMux := m .MatchWithWriters (cmux .HTTP2MatchHeaderFieldSendSettings ("content-type" , "application/grpc" ))
@@ -1131,8 +1141,13 @@ func startAPIEndpoint(ctx context.Context, cfg *Config, wg *sync.WaitGroup, serv
1131
1141
return true
1132
1142
}))
1133
1143
1144
+ metricsRegistry := prometheus .NewRegistry ()
1145
+ err = metricsRegistry .Register (grpcMetrics )
1146
+ if err != nil {
1147
+ log .WithError (err ).Error ("supervisor: failed to register grpc metrics" )
1148
+ }
1134
1149
metricStore := storage .NewDiskMetricStore ("" , time .Minute * 5 , prometheus .DefaultGatherer , nil )
1135
- metricsGatherer := prometheus.Gatherers {prometheus .GathererFunc (func () ([]* dto.MetricFamily , error ) {
1150
+ metricsGatherer := prometheus.Gatherers {metricsRegistry , prometheus .GathererFunc (func () ([]* dto.MetricFamily , error ) {
1136
1151
return metricStore .GetMetricFamilies (), nil
1137
1152
})}
1138
1153
0 commit comments