metrics

package
v1.1.18 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 15 Imported by: 8

Documentation

Index

Constants

View Source
const MetricsEnabledFlag = "metrics"

Variables

This section is empty.

Functions

func ToGRPCPromCounterOption

func ToGRPCPromCounterOption(opts *Options) grpcProm.CounterOption

To support grpc prometheus options

func ToGRPCPromHistogramOption

func ToGRPCPromHistogramOption(opts *Options) grpcProm.HistogramOption

Types

type Counter

type Counter interface {
	Inc()
	Add(float64)
}

Counter is a Metric that represents a single numerical value that only ever goes up. A Counter is typically used to count requests served, tasks completed, errors occurred, etc.

func NewCounter

func NewCounter(key string, opts ...Option) Counter

type CounterVec added in v1.0.9

type CounterVec interface {
	GetMetricWith(MetricsLabels) (Counter, error)
	GetMetricWithLabelValues(lvs ...string) (Counter, error)
}

CounterVec is returned by NewCounterVec.

func NewCounterVec added in v1.0.9

func NewCounterVec(key string, labels []string, opts ...Option) CounterVec

type DummyRegistry

type DummyRegistry struct {
}

func NewDummyRegistry

func NewDummyRegistry() *DummyRegistry

func (*DummyRegistry) Gather added in v1.1.18

func (d *DummyRegistry) Gather() ([]*dto.MetricFamily, error)

prom.Gatherer interface

func (*DummyRegistry) MustRegister added in v1.1.10

func (d *DummyRegistry) MustRegister(...prom.Collector)

prom.Registerer interface

func (*DummyRegistry) NewCounter

func (d *DummyRegistry) NewCounter(key string, opts ...Option) Counter

func (*DummyRegistry) NewCounterVec added in v1.0.9

func (d *DummyRegistry) NewCounterVec(key string, labels []string, opts ...Option) CounterVec

func (*DummyRegistry) NewGauge

func (d *DummyRegistry) NewGauge(key string, opts ...Option) Gauge

func (*DummyRegistry) NewGaugeVec added in v1.1.0

func (d *DummyRegistry) NewGaugeVec(key string, labels []string, opts ...Option) GaugeVec

func (*DummyRegistry) NewHistogram

func (d *DummyRegistry) NewHistogram(key string, opts ...Option) Histogram

func (*DummyRegistry) NewHistogramVec added in v1.0.8

func (d *DummyRegistry) NewHistogramVec(key string, labels []string, opts ...Option) HistogramVec

func (*DummyRegistry) NewHttpServerMetrics added in v1.0.1

func (d *DummyRegistry) NewHttpServerMetrics(opts ...Option) HttpServerMetrics

func (*DummyRegistry) NewServerMetrics

func (d *DummyRegistry) NewServerMetrics(opts ...Option) ServerMetrics

func (*DummyRegistry) NewTimer

func (d *DummyRegistry) NewTimer(key string, opts ...Option) Timer

func (*DummyRegistry) NewWorker

func (d *DummyRegistry) NewWorker(key string, opts ...Option) Worker

func (*DummyRegistry) Register added in v1.1.10

func (d *DummyRegistry) Register(prom.Collector) error

prom.Registerer interface

func (*DummyRegistry) ServeHTTP

func (d *DummyRegistry) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*DummyRegistry) Unregister added in v1.1.10

func (d *DummyRegistry) Unregister(prom.Collector) bool

prom.Registerer interface

type Gauge

type Gauge interface {
	Set(float64)
}

Gauge is a Metric that represents a single numerical value that can arbitrarily go up and down. A Gauge is typically used for measured values like temperatures or current memory usage.

func NewGauge

func NewGauge(key string, opts ...Option) Gauge

type GaugeVec added in v1.1.0

type GaugeVec interface {
	GetMetricWith(MetricsLabels) (Gauge, error)
	GetMetricWithLabelValues(lvs ...string) (Gauge, error)
}

GaugeVec is returned by NewGaugeVec.

func NewGaugeVec added in v1.1.0

func NewGaugeVec(key string, labels []string, opts ...Option) GaugeVec

type Histogram

type Histogram interface {
	Observe(float64)
}

A Histogram counts individual observations from an event or sample stream in configurable buckets. Similar to a summary, it also provides a sum of observations and an observation count.

func NewHistogram

func NewHistogram(key string, opts ...Option) Histogram

type HistogramVec added in v1.0.8

type HistogramVec interface {
	GetMetricWith(MetricsLabels) (Histogram, error)
	GetMetricWithLabelValues(lvs ...string) (Histogram, error)
}

HistogramVec is returned by NewHistogramVec.

func NewHistogramVec added in v1.0.8

func NewHistogramVec(key string, labels []string, opts ...Option) HistogramVec

type HttpMetrics added in v1.0.1

type HttpMetrics struct {
	// contains filtered or unexported fields
}

HttpMetrics represents a collection of metrics to be registered on a Prometheus metrics registry for a http server.

func NewHttpMetrics added in v1.0.1

func NewHttpMetrics(counterOpts ...grpcProm.CounterOption) *HttpMetrics

NewHttpMetrics returns a HttpMetrics object. Use a new instance of HttpMetrics 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 (*HttpMetrics) Collect added in v1.0.1

func (m *HttpMetrics) 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 (*HttpMetrics) Describe added in v1.0.1

func (m *HttpMetrics) 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 (*HttpMetrics) EnableHandlingTimeHistogram added in v1.0.1

func (m *HttpMetrics) EnableHandlingTimeHistogram(opts ...grpcProm.HistogramOption)

EnableHandlingTimeHistogram enables histograms being registered when registering the HttpMetrics on a Prometheus registry. Histograms can be expensive on Prometheus servers. It takes options to configure histogram options such as the defined buckets.

func (*HttpMetrics) Register deprecated added in v1.0.1

func (m *HttpMetrics) Register(r prom.Registerer) error

Register registers all server metrics in a given metrics registry. Depending on histogram options and whether they are enabled, histogram metrics are also registered.

Deprecated: HttpMetrics implements Prometheus Collector interface. You can register an instance of HttpMetrics directly by using prometheus.Register(m).

func (*HttpMetrics) ServeHTTP added in v1.0.1

func (m *HttpMetrics) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http.HandlerFunc)

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

type HttpServerMetrics added in v1.0.1

type HttpServerMetrics interface {
	ServeHTTP(w http.ResponseWriter, req *http.Request, next http.HandlerFunc)
}

HttpServerMetrics is an integrated metric collector to measure count of any kind of error and elapsed time of each http call.

func NewHttpServerMetrics added in v1.0.1

func NewHttpServerMetrics(opts ...Option) HttpServerMetrics

type MetricsLabels added in v1.0.9

type MetricsLabels = prom.Labels

type Option

type Option func(opt *Options)

func Labels

func Labels(lbs map[string]string) Option

func Namespace

func Namespace(namespace string) Option

func Subsystem

func Subsystem(subsystem string) Option

type Options

type Options struct {
	Namespace string
	Subsystem string
	Labels    map[string]string
}

func NewOptions

func NewOptions(namespace, subsystem string, lbs map[string]string) *Options

type PrometheusRegistry

type PrometheusRegistry struct {
	*prom.Registry
	// contains filtered or unexported fields
}

func NewPrometheusRegistry

func NewPrometheusRegistry() *PrometheusRegistry

func (*PrometheusRegistry) AppendLabels

func (p *PrometheusRegistry) AppendLabels(labels map[string]string)

func (*PrometheusRegistry) NewCounter

func (p *PrometheusRegistry) NewCounter(key string, opts ...Option) Counter

func (*PrometheusRegistry) NewCounterVec added in v1.0.9

func (p *PrometheusRegistry) NewCounterVec(key string, labelNames []string, opts ...Option) CounterVec

func (*PrometheusRegistry) NewGauge

func (p *PrometheusRegistry) NewGauge(key string, opts ...Option) Gauge

func (*PrometheusRegistry) NewGaugeVec added in v1.1.0

func (p *PrometheusRegistry) NewGaugeVec(key string, labelNames []string, opts ...Option) GaugeVec

func (*PrometheusRegistry) NewHistogram

func (p *PrometheusRegistry) NewHistogram(key string, opts ...Option) Histogram

func (*PrometheusRegistry) NewHistogramVec added in v1.0.8

func (p *PrometheusRegistry) NewHistogramVec(key string, labels []string, opts ...Option) HistogramVec

func (*PrometheusRegistry) NewHttpServerMetrics added in v1.0.1

func (p *PrometheusRegistry) NewHttpServerMetrics(opts ...Option) HttpServerMetrics

func (*PrometheusRegistry) NewServerMetrics

func (p *PrometheusRegistry) NewServerMetrics(opts ...Option) ServerMetrics

func (*PrometheusRegistry) NewTimer

func (p *PrometheusRegistry) NewTimer(key string, opts ...Option) Timer

func (*PrometheusRegistry) NewWorker

func (p *PrometheusRegistry) NewWorker(key string, opts ...Option) Worker

func (*PrometheusRegistry) ServeHTTP

func (p *PrometheusRegistry) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*PrometheusRegistry) SetNamespace

func (p *PrometheusRegistry) SetNamespace(namespace string)

type Registry

type Registry interface {
	prom.Registerer
	prom.Gatherer

	NewHttpServerMetrics(opts ...Option) HttpServerMetrics
	NewServerMetrics(opts ...Option) ServerMetrics
	NewCounter(key string, opts ...Option) Counter
	NewGauge(key string, opts ...Option) Gauge
	NewGaugeVec(key string, labels []string, opts ...Option) GaugeVec
	NewHistogram(key string, opts ...Option) Histogram
	NewHistogramVec(key string, labels []string, opts ...Option) HistogramVec
	NewCounterVec(key string, labels []string, opts ...Option) CounterVec
	NewTimer(key string, opts ...Option) Timer
	NewWorker(key string, opts ...Option) Worker

	// ServeHTTP is used to display all metric values through http request
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Registry is a metrics gather

var DefaultRegistry Registry = NewDummyRegistry()

type ServerMetrics

type ServerMetrics interface {
	InitializeMetrics(*grpc.Server)
	StreamServerInterceptor() func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
	UnaryServerInterceptor() func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
}

ServerMetrics is an integrated metric collector to measure count of any kind of error and elapsed time of each grpc method.

func NewServerMetrics

func NewServerMetrics(opts ...Option) ServerMetrics

type Timer

type Timer interface {
	Observe(time.Time)
}

Timer represents a Histogram Metrics to observe the time duration according to given begin time. Timer is usually used to time a function call in the following way:

func TimeMe() {
    begin := time.Now()
    defer Timer.Observe(begin)
}

func NewTimer

func NewTimer(key string, opts ...Option) Timer

type Worker

type Worker interface {
	Observe(time.Time, error)
}

Worker includes Timer Metrics to observe the time duration according to given begin time, and counter Metreic to gather the success count and fail count. Worker is usually used to measure a function call in the following way:

func MeasureMe()(err error) {
    begin := time.Now()
    defer Worker.Observe(begin, err)
}

func NewWorker

func NewWorker(key string, opts ...Option) Worker

Jump to

Keyboard shortcuts

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