Documentation ¶
Index ¶
- Constants
- Variables
- func EnableClientHandlingTimeHistogram(opts ...HistogramOption)
- func EnableHandlingTimeHistogram(opts ...HistogramOption)
- func Register(server *grpc.Server)
- type ClientMetrics
- func (m *ClientMetrics) Collect(ch chan<- prom.Metric)
- func (m *ClientMetrics) Describe(ch chan<- *prom.Desc)
- func (m *ClientMetrics) EnableClientHandlingTimeHistogram(opts ...HistogramOption)
- func (m *ClientMetrics) StreamClientInterceptor() ...
- func (m *ClientMetrics) UnaryClientInterceptor() func(ctx context.Context, method string, req, reply interface{}, ...) error
- type CounterOption
- type HistogramOption
- type ServerMetrics
- func (m *ServerMetrics) Collect(ch chan<- prom.Metric)
- func (m *ServerMetrics) Describe(ch chan<- *prom.Desc)
- func (m *ServerMetrics) EnableHandlingTimeHistogram(opts ...HistogramOption)
- func (m *ServerMetrics) InitializeMetrics(server *grpc.Server)
- func (m *ServerMetrics) StreamServerInterceptor() ...
- func (m *ServerMetrics) UnaryServerInterceptor() ...
Constants ¶
const ( Unary grpcType = "unary" ClientStream grpcType = "client_stream" ServerStream grpcType = "server_stream" BidiStream grpcType = "bidi_stream" )
Variables ¶
var ( // DefaultClientMetrics is the default instance of ClientMetrics. It is // intended to be used in conjunction the default Prometheus metrics // registry. DefaultClientMetrics = NewClientMetrics() // UnaryClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Unary RPCs. UnaryClientInterceptor = DefaultClientMetrics.UnaryClientInterceptor() // StreamClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Streaming RPCs. StreamClientInterceptor = DefaultClientMetrics.StreamClientInterceptor() )
var ( // DefaultServerMetrics is the default instance of ServerMetrics. It is // intended to be used in conjunction the default Prometheus metrics // registry. DefaultServerMetrics = NewServerMetrics() // UnaryServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Unary RPCs. UnaryServerInterceptor = DefaultServerMetrics.UnaryServerInterceptor() // StreamServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Streaming RPCs. StreamServerInterceptor = DefaultServerMetrics.StreamServerInterceptor() )
Functions ¶
func EnableClientHandlingTimeHistogram ¶
func EnableClientHandlingTimeHistogram(opts ...HistogramOption)
EnableClientHandlingTimeHistogram turns on recording of handling time of RPCs. Histogram metrics can be very expensive for Prometheus to retain and query. This function acts on the DefaultClientMetrics variable and the default Prometheus metrics registry.
func EnableHandlingTimeHistogram ¶
func EnableHandlingTimeHistogram(opts ...HistogramOption)
EnableHandlingTimeHistogram turns on recording of handling time of RPCs. Histogram metrics can be very expensive for Prometheus to retain and query. This function acts on the DefaultServerMetrics variable and the default Prometheus metrics registry.
func Register ¶
Register takes a gRPC server and pre-initializes all counters to 0. This allows for easier monitoring in Prometheus (no missing metrics), and should be called *after* all services have been registered with the server. This function acts on the DefaultServerMetrics variable.
Types ¶
type ClientMetrics ¶
type ClientMetrics struct {
// contains filtered or unexported fields
}
ClientMetrics represents a collection of metrics to be registered on a Prometheus metrics registry for a gRPC client.
func NewClientMetrics ¶
func NewClientMetrics(counterOpts ...CounterOption) *ClientMetrics
NewClientMetrics returns a ClientMetrics object. Use a new instance of ClientMetrics 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 (*ClientMetrics) Collect ¶
func (m *ClientMetrics) Collect(ch chan<- prom.Metric)
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 (*ClientMetrics) Describe ¶
func (m *ClientMetrics) Describe(ch chan<- *prom.Desc)
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 (*ClientMetrics) EnableClientHandlingTimeHistogram ¶
func (m *ClientMetrics) EnableClientHandlingTimeHistogram(opts ...HistogramOption)
EnableClientHandlingTimeHistogram turns on recording of handling time of RPCs. Histogram metrics can be very expensive for Prometheus to retain and query.
func (*ClientMetrics) StreamClientInterceptor ¶
func (m *ClientMetrics) StreamClientInterceptor() func(ctx context.Context, desc *grpc.StreamDesc, cc *grpc.ClientConn, method string, streamer grpc.Streamer, opts ...grpc.CallOption) (grpc.ClientStream, error)
StreamClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Streaming RPCs.
func (*ClientMetrics) UnaryClientInterceptor ¶
func (m *ClientMetrics) UnaryClientInterceptor() func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error
UnaryClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Unary RPCs.
type CounterOption ¶
type CounterOption func(*prom.CounterOpts)
A CounterOption lets you add options to Counter metrics using With* funcs.
func WithConstLabels ¶
func WithConstLabels(labels prom.Labels) CounterOption
WithConstLabels allows you to add ConstLabels to Counter metrics.
type HistogramOption ¶
type HistogramOption func(*prom.HistogramOpts)
A HistogramOption lets you add options to Histogram metrics using With* funcs.
func WithHistogramBuckets ¶
func WithHistogramBuckets(buckets []float64) HistogramOption
WithHistogramBuckets allows you to specify custom bucket ranges for histograms if EnableHandlingTimeHistogram is on.
func WithHistogramConstLabels ¶
func WithHistogramConstLabels(labels prom.Labels) HistogramOption
WithHistogramConstLabels allows you to add custom ConstLabels to histograms metrics.
type ServerMetrics ¶
type ServerMetrics struct {
// contains filtered or unexported fields
}
ServerMetrics represents a collection of metrics to be registered on a Prometheus metrics registry for a gRPC server.
func NewServerMetrics ¶
func NewServerMetrics(counterOpts ...CounterOption) *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 (*ServerMetrics) Collect ¶
func (m *ServerMetrics) Collect(ch chan<- prom.Metric)
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 (*ServerMetrics) Describe ¶
func (m *ServerMetrics) Describe(ch chan<- *prom.Desc)
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 (*ServerMetrics) EnableHandlingTimeHistogram ¶
func (m *ServerMetrics) EnableHandlingTimeHistogram(opts ...HistogramOption)
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 (*ServerMetrics) InitializeMetrics ¶
func (m *ServerMetrics) InitializeMetrics(server *grpc.Server)
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 (*ServerMetrics) StreamServerInterceptor ¶
func (m *ServerMetrics) StreamServerInterceptor() func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
StreamServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Streaming RPCs.
func (*ServerMetrics) UnaryServerInterceptor ¶
func (m *ServerMetrics) UnaryServerInterceptor() func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
UnaryServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Unary RPCs.