go-grpc-prometheus: github.com/grpc-ecosystem/go-grpc-prometheus Index | Files | Directories

package grpc_prometheus

import "github.com/grpc-ecosystem/go-grpc-prometheus"

Index

Package Files

client.go client_metrics.go client_reporter.go metric_options.go server.go server_metrics.go server_reporter.go util.go

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()
)

func EnableClientHandlingTimeHistogram Uses

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 EnableClientStreamReceiveTimeHistogram Uses

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 Uses

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 Uses

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 Uses

func Register(server *grpc.Server)

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.

type ClientMetrics Uses

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 Uses

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 Uses

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 Uses

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 Uses

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) EnableClientStreamReceiveTimeHistogram Uses

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 Uses

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) StreamClientInterceptor Uses

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 Uses

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 Uses

type CounterOption func(*prom.CounterOpts)

A CounterOption lets you add options to Counter metrics using With* funcs.

func WithConstLabels Uses

func WithConstLabels(labels prom.Labels) CounterOption

WithConstLabels allows you to add ConstLabels to Counter metrics.

type HistogramOption Uses

type HistogramOption func(*prom.HistogramOpts)

A HistogramOption lets you add options to Histogram metrics using With* funcs.

func WithHistogramBuckets Uses

func WithHistogramBuckets(buckets []float64) HistogramOption

WithHistogramBuckets allows you to specify custom bucket ranges for histograms if EnableHandlingTimeHistogram is on.

func WithHistogramConstLabels Uses

func WithHistogramConstLabels(labels prom.Labels) HistogramOption

WithHistogramConstLabels allows you to add custom ConstLabels to histograms metrics.

type ServerMetrics Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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.

Directories

PathSynopsis
examples/testproto

Package grpc_prometheus imports 8 packages (graph) and is imported by 298 packages. Updated 2019-04-02. Refresh now. Tools for package owners.