type ServerMetrics … // NewServerMetrics returns a ServerMetrics object. Use a new instance of // ServerMetrics when not using the default Prometheus metrics registry, for // example when wanting to control which metrics are added to a registry as // opposed to automatically adding metrics via init functions. func NewServerMetrics(counterOpts ...CounterOption) *ServerMetrics { … } // EnableHandlingTimeHistogram enables histograms being registered when // registering the ServerMetrics on a Prometheus registry. Histograms can be // expensive on Prometheus servers. It takes options to configure histogram // options such as the defined buckets. func (m *ServerMetrics) EnableHandlingTimeHistogram(opts ...HistogramOption) { … } // Describe sends the super-set of all possible descriptors of metrics // collected by this Collector to the provided channel and returns once // the last descriptor has been sent. func (m *ServerMetrics) Describe(ch chan<- *prom.Desc) { … } // Collect is called by the Prometheus registry when collecting // metrics. The implementation sends each collected metric via the // provided channel and returns once the last metric has been sent. func (m *ServerMetrics) Collect(ch chan<- prom.Metric) { … } // UnaryServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Unary RPCs. func (m *ServerMetrics) UnaryServerInterceptor() func(ctx context.Context, req interface{ … } // StreamServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Streaming RPCs. func (m *ServerMetrics) StreamServerInterceptor() func(srv interface{ … } // InitializeMetrics initializes all metrics, with their appropriate null // value, for all gRPC methods registered on a gRPC server. This is useful, to // ensure that all metrics exist when collecting and querying. func (m *ServerMetrics) InitializeMetrics(server *grpc.Server) { … } func streamRPCType(info *grpc.StreamServerInfo) grpcType { … } type monitoredServerStream … func (s *monitoredServerStream) SendMsg(m interface{ … } func (s *monitoredServerStream) RecvMsg(m interface{ … } // preRegisterMethod is invoked on Register of a Server, allowing all gRPC services labels to be pre-populated. func preRegisterMethod(metrics *ServerMetrics, serviceName string, mInfo *grpc.MethodInfo) { … }