MCPcopy
hub / github.com/grafana/dskit / NewStatsHandler

Function NewStatsHandler

middleware/grpc_stats.go:17–37  ·  view source on GitHub ↗

NewStatsHandler creates handler that can be added to gRPC server options to track received and sent message sizes.

(reg prometheus.Registerer, receivedPayloadSize, sentPayloadSize *prometheus.HistogramVec, inflightRequests *prometheus.GaugeVec, collectMaxStreamsByConn bool)

Source from the content-addressed store, hash-verified

15
16// NewStatsHandler creates handler that can be added to gRPC server options to track received and sent message sizes.
17func NewStatsHandler(reg prometheus.Registerer, receivedPayloadSize, sentPayloadSize *prometheus.HistogramVec, inflightRequests *prometheus.GaugeVec, collectMaxStreamsByConn bool) stats.Handler {
18 var streamTracker *StreamTracker
19 if collectMaxStreamsByConn {
20 grpcConcurrentStreamsByConnMax := prometheus.NewDesc(
21 "grpc_concurrent_streams_by_conn_max",
22 "The current number of concurrent streams in the connection with the most concurrent streams.",
23 []string{},
24 prometheus.Labels{},
25 )
26 streamTracker = NewStreamTracker(grpcConcurrentStreamsByConnMax)
27 reg.MustRegister(streamTracker)
28 }
29
30 return &grpcStatsHandler{
31 receivedPayloadSize: receivedPayloadSize,
32 sentPayloadSize: sentPayloadSize,
33 inflightRequests: inflightRequests,
34
35 grpcConcurrentStreamsTracker: streamTracker,
36 }
37}
38
39type grpcStatsHandler struct {
40 receivedPayloadSize *prometheus.HistogramVec

Callers 6

newServerFunction · 0.92
newBenchStatsHandlerFunction · 0.85
TestGrpcStatsFunction · 0.85
TestGrpcStatsStreamingFunction · 0.85
TestGrpcStatsMaxStreamsFunction · 0.85

Calls 2

NewStreamTrackerFunction · 0.85
MustRegisterMethod · 0.80

Tested by 5

newBenchStatsHandlerFunction · 0.68
TestGrpcStatsFunction · 0.68
TestGrpcStatsStreamingFunction · 0.68
TestGrpcStatsMaxStreamsFunction · 0.68