Documentation ¶
Index ¶
- Constants
- Variables
- func EnableClientHandlingTimeHistogram(opts ...HistogramOption)
- func EnableClientMeasureBandwidth()
- func EnableClientStreamReceiveTimeHistogram(opts ...HistogramOption)
- func EnableClientStreamSendTimeHistogram(opts ...HistogramOption)
- func EnableHandlingTimeHistogram(opts ...HistogramOption)
- func EnableMeasureBandwidth()
- 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) EnableClientMeasureBandwidth()
- func (m *ClientMetrics) EnableClientStreamReceiveTimeHistogram(opts ...HistogramOption)
- func (m *ClientMetrics) EnableClientStreamSendTimeHistogram(opts ...HistogramOption)
- func (m *ClientMetrics) StatsHandler() *StatsHandler
- 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) EnableMeasureBandwidth()
- func (m *ServerMetrics) InitializeMetrics(server *grpc.Server)
- func (m *ServerMetrics) StatsHandler() *StatsHandler
- func (m *ServerMetrics) StreamServerInterceptor() ...
- func (m *ServerMetrics) UnaryServerInterceptor() ...
- type StatsHandler
- func (h StatsHandler) HandleConn(ctx context.Context, s stats.ConnStats)
- func (h StatsHandler) HandleRPC(ctx context.Context, s stats.RPCStats)
- func (h StatsHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context
- func (h StatsHandler) TagRPC(ctx context.Context, s *stats.RPCTagInfo) context.Context
- type StatsHandlerOptions
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() // ClientStatsHandler is a gRPC stats handler that provides Prometheus monitoring for various grpc request flow events. ClientStatsHandler = DefaultClientMetrics.StatsHandler() )
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() // ServerStatsHandler is a gRPC stats handler that provides Prometheus monitoring for various grpc request flow events. ServerStatsHandler = DefaultServerMetrics.StatsHandler() )
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 EnableClientMeasureBandwidth ¶
func EnableClientMeasureBandwidth()
EnableMeasureBandwidth turns on recording of in and out payload sizes
func EnableClientStreamReceiveTimeHistogram ¶
func EnableClientStreamReceiveTimeHistogram(opts ...HistogramOption)
EnableClientStreamReceiveTimeHistogram turns on recording of single message receive time of streaming RPCs. This function acts on the DefaultClientMetrics variable and the default Prometheus metrics registry.
func EnableClientStreamSendTimeHistogram ¶
func EnableClientStreamSendTimeHistogram(opts ...HistogramOption)
EnableClientStreamReceiveTimeHistogram turns on recording of single message send time of streaming RPCs. 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 EnableMeasureBandwidth ¶
func EnableMeasureBandwidth()
EnableMeasureBandwidth turns on recording of in and out payload sizes
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) EnableClientMeasureBandwidth ¶
func (m *ClientMetrics) EnableClientMeasureBandwidth()
EnableClientMeasureBandwidth enables counters to measure in and out payload sizes
func (*ClientMetrics) EnableClientStreamReceiveTimeHistogram ¶
func (m *ClientMetrics) EnableClientStreamReceiveTimeHistogram(opts ...HistogramOption)
EnableClientStreamReceiveTimeHistogram turns on recording of single message receive time of streaming RPCs. Histogram metrics can be very expensive for Prometheus to retain and query.
func (*ClientMetrics) EnableClientStreamSendTimeHistogram ¶
func (m *ClientMetrics) EnableClientStreamSendTimeHistogram(opts ...HistogramOption)
EnableClientStreamSendTimeHistogram turns on recording of single message send time of streaming RPCs. Histogram metrics can be very expensive for Prometheus to retain and query.
func (*ClientMetrics) StatsHandler ¶
func (m *ClientMetrics) StatsHandler() *StatsHandler
StatsHandler is a gRPC stats handler that provides Prometheus monitoring for various grpc request flow events.
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) EnableMeasureBandwidth ¶
func (m *ServerMetrics) EnableMeasureBandwidth()
EnableMeasureBandwidth enables counters to measure in and out payload sizes
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) StatsHandler ¶
func (m *ServerMetrics) StatsHandler() *StatsHandler
StatsHandler is a gRPC stats handler that provides Prometheus monitoring for various grpc request flow events.
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.
type StatsHandler ¶
type StatsHandler struct {
// contains filtered or unexported fields
}
StatsHandler is useful for recording various kinds of grpc metrics.
func NewStatsHandler ¶
func NewStatsHandler(opts StatsHandlerOptions) *StatsHandler
NewStatsHandler creates a StatsHandler for use in recording various kinds of grpc metrics.
func (StatsHandler) HandleConn ¶
func (h StatsHandler) HandleConn(ctx context.Context, s stats.ConnStats)
HandleConn is an implementation of a statshandler callback
func (StatsHandler) HandleRPC ¶
func (h StatsHandler) HandleRPC(ctx context.Context, s stats.RPCStats)
HandleRPC is an implementation of a statshandler callback
func (StatsHandler) TagConn ¶
func (h StatsHandler) TagConn(ctx context.Context, _ *stats.ConnTagInfo) context.Context
TagConn is an implementation of a statshandler callback
func (StatsHandler) TagRPC ¶
func (h StatsHandler) TagRPC(ctx context.Context, s *stats.RPCTagInfo) context.Context
TagRPC is an implementation of a statshandler callback
type StatsHandlerOptions ¶
type StatsHandlerOptions struct {
// contains filtered or unexported fields
}
StatsHandlerOptions control various aspects of what we do with grpc stats-related callbacks