prometheus

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 7 Imported by: 131

Documentation

Overview

Package prometheus provides a standalone interceptor for metrics. It's next iteration of deprecated https://github.com/grpc-ecosystem/go-grpc-prometheus. See https://github.com/grpc-ecosystem/go-grpc-middleware/tree/main/examples for example.

Index

Constants

View Source
const (
	Unary        grpcType = "unary"
	ClientStream grpcType = "client_stream"
	ServerStream grpcType = "server_stream"
	BidiStream   grpcType = "bidi_stream"
)

grpcType describes all types of grpc connection.

Variables

This section is empty.

Functions

func FromError

func FromError(err error) *status.Status

FromError returns a grpc status. If the error code is neither a valid grpc status nor a context error, codes.Unknown will be set.

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(opts ...ClientMetricsOption) *ClientMetrics

NewClientMetrics returns a new ClientMetrics object. NOTE: Remember to register ClientMetrics object using prometheus registry e.g. prometheus.MustRegister(myClientMetrics).

func (*ClientMetrics) Collect

func (m *ClientMetrics) Collect(ch chan<- prometheus.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<- *prometheus.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) StreamClientInterceptor

func (m *ClientMetrics) StreamClientInterceptor(opts ...Option) grpc.StreamClientInterceptor

StreamClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Streaming RPCs.

func (*ClientMetrics) UnaryClientInterceptor

func (m *ClientMetrics) UnaryClientInterceptor(opts ...Option) grpc.UnaryClientInterceptor

UnaryClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Unary RPCs.

type ClientMetricsOption

type ClientMetricsOption func(*clientMetricsConfig)

func WithClientCounterOptions

func WithClientCounterOptions(opts ...CounterOption) ClientMetricsOption

func WithClientHandlingTimeHistogram

func WithClientHandlingTimeHistogram(opts ...HistogramOption) ClientMetricsOption

WithClientHandlingTimeHistogram turns on recording of handling time of RPCs. Histogram metrics can be very expensive for Prometheus to retain and query.

func WithClientStreamRecvHistogram

func WithClientStreamRecvHistogram(opts ...HistogramOption) ClientMetricsOption

WithClientStreamRecvHistogram turns on recording of single message receive time of streaming RPCs. Histogram metrics can be very expensive for Prometheus to retain and query.

func WithClientStreamSendHistogram

func WithClientStreamSendHistogram(opts ...HistogramOption) ClientMetricsOption

WithClientStreamSendHistogram turns on recording of single message send time of streaming RPCs. Histogram metrics can be very expensive for Prometheus to retain and query.

type CounterOption

type CounterOption func(*prometheus.CounterOpts)

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

func WithConstLabels

func WithConstLabels(labels prometheus.Labels) CounterOption

WithConstLabels allows you to add ConstLabels to Counter metrics.

func WithSubsystem

func WithSubsystem(subsystem string) CounterOption

WithSubsystem allows you to add a Subsystem to Counter metrics.

type HistogramOption

type HistogramOption func(*prometheus.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 prometheus.Labels) HistogramOption

WithHistogramConstLabels allows you to add custom ConstLabels to histograms metrics.

func WithHistogramOpts

func WithHistogramOpts(opts *prometheus.HistogramOpts) HistogramOption

WithHistogramOpts allows you to specify HistogramOpts but makes sure the correct name and label is used. This function is helpful when specifying more than just the buckets, like using NativeHistograms.

func WithHistogramSubsystem

func WithHistogramSubsystem(subsystem string) HistogramOption

WithHistogramSubsystem allows you to add a Subsystem to histograms metrics.

type Kind

type Kind string

Kind describes whether interceptor is a client or server type.

const (
	KindClient Kind = "client"
	KindServer Kind = "server"
)

Enum for Client and Server Kind.

type Option

type Option func(*config)

An Option lets you add options to prometheus interceptors using With* funcs.

func WithExemplarFromContext

func WithExemplarFromContext(exemplarFn exemplarFromCtxFn) Option

WithExemplarFromContext sets function that will be used to deduce exemplar for all counter and histogram 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(opts ...ServerMetricsOption) *ServerMetrics

NewServerMetrics returns a new ServerMetrics object that has server interceptor methods. NOTE: Remember to register ServerMetrics object by using prometheus registry e.g. prometheus.MustRegister(myServerMetrics).

func (*ServerMetrics) Collect

func (m *ServerMetrics) Collect(ch chan<- prometheus.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<- *prometheus.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) InitializeMetrics

func (m *ServerMetrics) InitializeMetrics(server reflection.ServiceInfoProvider)

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. NOTE: This might add significant cardinality and might not be needed in future version of Prometheus (created timestamp).

func (*ServerMetrics) StreamServerInterceptor

func (m *ServerMetrics) StreamServerInterceptor(opts ...Option) grpc.StreamServerInterceptor

StreamServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Streaming RPCs.

func (*ServerMetrics) UnaryServerInterceptor

func (m *ServerMetrics) UnaryServerInterceptor(opts ...Option) grpc.UnaryServerInterceptor

UnaryServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Unary RPCs.

type ServerMetricsOption

type ServerMetricsOption func(*serverMetricsConfig)

func WithServerCounterOptions

func WithServerCounterOptions(opts ...CounterOption) ServerMetricsOption

WithServerCounterOptions sets counter options.

func WithServerHandlingTimeHistogram

func WithServerHandlingTimeHistogram(opts ...HistogramOption) ServerMetricsOption

WithServerHandlingTimeHistogram turns on recording of handling time of RPCs. Histogram metrics can be very expensive for Prometheus to retain and query.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL