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)
| 15 | |
| 16 | // NewStatsHandler creates handler that can be added to gRPC server options to track received and sent message sizes. |
| 17 | func 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 | |
| 39 | type grpcStatsHandler struct { |
| 40 | receivedPayloadSize *prometheus.HistogramVec |