metrics

package
v0.16.16 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Apache-2.0, MIT Imports: 12 Imported by: 9

Documentation

Overview

Package metrics implements collection of common performance metrics.

The metrics can be exposed in multiple formats. At this moment are:

* Coda Hale format. * Prometheus format.

For CodaHale format it uses the Go implementation of the Go Coda Hale metrics library:

https://github.com/dropwizard/metrics https://github.com/rcrowley/go-metrics

For Prometheus format, it uses Prometheus Go official client library:

https://github.com/prometheus/client_golang

The collected metrics include detailed information about Skipper's relevant processes while serving requests - looking up routes, filters (aggregate and individual), backend communication and forwarding the response to the client.

Options

To enable metrics, it needs to be initialized with a Listener address. In this case, Skipper will start an additional http listener, where the current metrics values can be downloaded.

You can define a custom Prefix to every reported metrics key. This allows you to avoid conflicts between Skipper's metrics and other systems if you aggregate them later in some monitoring system. The default prefix is "skipper."

You can also enable some Go garbage collector and runtime metrics using EnableDebugGcMetrics and EnableRuntimeMetrics, respectively.

REST API

This listener accepts GET requests on the /metrics endpoint like any other REST api. A request to "/metrics" should return a JSON response including all the collected metrics if CodaHale format is used, or in Plain text if Prometheus format is used. Please note that a lot of metrics are created lazily whenever a request triggers them. This means that the API response will depend on the current routes and the filters used. In the case there are no metrics due to inactivity, the API will return 404 if CodaHale is used or 200 if Prometheus is used.

If you use CodaHale format you can also query for specific metrics, individually or by prefix matching. You can either use the metrics key name and you should get back only the values for that particular key or a prefix in which case you should get all the metrics that share the same prefix. If you request an unknown key or prefix the response will be an HTTP 404.

Prometheus doesn't need to support this, the Prometheus server will grab everything.

Index

Constants

View Source
const (
	KeyRouteLookup                = "routelookup"
	KeyRouteFailure               = "routefailure"
	KeyFilterRequest              = "filter.%s.request"
	KeyFiltersRequest             = "allfilters.request.%s"
	KeyAllFiltersRequestCombined  = "allfilters.combined.request"
	KeyProxyBackend               = "backend.%s"
	KeyProxyBackendCombined       = "all.backend"
	KeyProxyBackendHost           = "backendhost.%s"
	KeyFilterResponse             = "filter.%s.response"
	KeyFiltersResponse            = "allfilters.response.%s"
	KeyAllFiltersResponseCombined = "allfilters.combined.response"
	KeyResponse                   = "response.%d.%s.skipper.%s"
	KeyResponseCombined           = "all.response.%d.%s.skipper"
	Key5xxsBackend                = "all.backend.5xx"

	KeyErrorsBackend   = "errors.backend.%s"
	KeyErrorsStreaming = "errors.streaming.%s"
)

Variables

This section is empty.

Functions

func NewDefaultHandler added in v0.9.141

func NewDefaultHandler(o Options) http.Handler

NewDefaultHandler returns a default metrics handler.

func NewHandler added in v0.9.70

func NewHandler(o Options, m Metrics) http.Handler

NewHandler returns a collection of metrics handlers.

Types

type All added in v0.9.169

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

func NewAll added in v0.9.169

func NewAll(o Options) *All

func (*All) IncCounter added in v0.9.169

func (a *All) IncCounter(key string)

func (*All) IncCounterBy added in v0.10.113

func (a *All) IncCounterBy(key string, value int64)

func (*All) IncErrorsBackend added in v0.9.169

func (a *All) IncErrorsBackend(routeId string)

func (*All) IncErrorsStreaming added in v0.9.169

func (a *All) IncErrorsStreaming(routeId string)

func (*All) IncFloatCounterBy added in v0.10.153

func (a *All) IncFloatCounterBy(key string, value float64)

func (*All) IncRoutingFailures added in v0.9.169

func (a *All) IncRoutingFailures()

func (*All) MeasureAllFiltersRequest added in v0.9.169

func (a *All) MeasureAllFiltersRequest(routeId string, start time.Time)

func (*All) MeasureAllFiltersResponse added in v0.9.169

func (a *All) MeasureAllFiltersResponse(routeId string, start time.Time)

func (*All) MeasureBackend added in v0.9.169

func (a *All) MeasureBackend(routeId string, start time.Time)

func (*All) MeasureBackend5xx added in v0.9.169

func (a *All) MeasureBackend5xx(t time.Time)

func (*All) MeasureBackendHost added in v0.9.169

func (a *All) MeasureBackendHost(routeBackendHost string, start time.Time)

func (*All) MeasureFilterRequest added in v0.9.169

func (a *All) MeasureFilterRequest(filterName string, start time.Time)

func (*All) MeasureFilterResponse added in v0.9.169

func (a *All) MeasureFilterResponse(filterName string, start time.Time)

func (*All) MeasureResponse added in v0.9.169

func (a *All) MeasureResponse(code int, method string, routeId string, start time.Time)

func (*All) MeasureRouteLookup added in v0.9.169

func (a *All) MeasureRouteLookup(start time.Time)

func (*All) MeasureServe added in v0.9.169

func (a *All) MeasureServe(routeId, host, method string, code int, start time.Time)

func (*All) MeasureSince added in v0.9.169

func (a *All) MeasureSince(key string, start time.Time)

func (*All) RegisterHandler added in v0.9.169

func (a *All) RegisterHandler(path string, handler *http.ServeMux)

func (*All) UpdateGauge added in v0.10.59

func (a *All) UpdateGauge(key string, v float64)

type CodaHale added in v0.9.141

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

CodaHale is the CodaHale format backend, implements Metrics interface in DropWizard's CodaHale metrics format.

func NewCodaHale added in v0.9.141

func NewCodaHale(o Options) *CodaHale

NewCodaHale returns a new CodaHale backend of metrics.

func NewVoid

func NewVoid() *CodaHale

func (*CodaHale) CreateHandler added in v0.9.169

func (c *CodaHale) CreateHandler(path string) http.Handler

func (*CodaHale) IncCounter added in v0.9.141

func (c *CodaHale) IncCounter(key string)

func (*CodaHale) IncCounterBy added in v0.10.113

func (c *CodaHale) IncCounterBy(key string, value int64)

func (*CodaHale) IncErrorsBackend added in v0.9.141

func (c *CodaHale) IncErrorsBackend(routeId string)

func (*CodaHale) IncErrorsStreaming added in v0.9.141

func (c *CodaHale) IncErrorsStreaming(routeId string)

func (*CodaHale) IncFloatCounterBy added in v0.10.153

func (c *CodaHale) IncFloatCounterBy(key string, value float64)

func (*CodaHale) IncRoutingFailures added in v0.9.141

func (c *CodaHale) IncRoutingFailures()

func (*CodaHale) MeasureAllFiltersRequest added in v0.9.141

func (c *CodaHale) MeasureAllFiltersRequest(routeId string, start time.Time)

func (*CodaHale) MeasureAllFiltersResponse added in v0.9.141

func (c *CodaHale) MeasureAllFiltersResponse(routeId string, start time.Time)

func (*CodaHale) MeasureBackend added in v0.9.141

func (c *CodaHale) MeasureBackend(routeId string, start time.Time)

func (*CodaHale) MeasureBackend5xx added in v0.9.141

func (c *CodaHale) MeasureBackend5xx(t time.Time)

func (*CodaHale) MeasureBackendHost added in v0.9.141

func (c *CodaHale) MeasureBackendHost(routeBackendHost string, start time.Time)

func (*CodaHale) MeasureFilterRequest added in v0.9.141

func (c *CodaHale) MeasureFilterRequest(filterName string, start time.Time)

func (*CodaHale) MeasureFilterResponse added in v0.9.141

func (c *CodaHale) MeasureFilterResponse(filterName string, start time.Time)

func (*CodaHale) MeasureResponse added in v0.9.141

func (c *CodaHale) MeasureResponse(code int, method string, routeId string, start time.Time)

func (*CodaHale) MeasureRouteLookup added in v0.9.141

func (c *CodaHale) MeasureRouteLookup(start time.Time)

func (*CodaHale) MeasureServe added in v0.9.141

func (c *CodaHale) MeasureServe(routeId, host, method string, code int, start time.Time)

func (*CodaHale) MeasureSince added in v0.9.141

func (c *CodaHale) MeasureSince(key string, start time.Time)

func (*CodaHale) RegisterHandler added in v0.9.141

func (c *CodaHale) RegisterHandler(path string, handler *http.ServeMux)

func (*CodaHale) UpdateGauge added in v0.10.59

func (c *CodaHale) UpdateGauge(key string, v float64)

type Kind added in v0.9.141

type Kind int

Kind is the type a metrics expose backend can be.

const (
	UnkownKind   Kind = 0
	CodaHaleKind Kind = 1 << iota
	PrometheusKind
	AllKind = CodaHaleKind | PrometheusKind
)

func ParseMetricsKind added in v0.9.141

func ParseMetricsKind(t string) Kind

ParseMetricsKind parses an string and returns the correct Metrics kind.

func (Kind) String added in v0.9.141

func (k Kind) String() string

type Metrics

type Metrics interface {
	// Implements the `filter.Metrics` interface.
	MeasureSince(key string, start time.Time)
	IncCounter(key string)
	IncCounterBy(key string, value int64)
	IncFloatCounterBy(key string, value float64)
	// Additional methods
	MeasureRouteLookup(start time.Time)
	MeasureFilterRequest(filterName string, start time.Time)
	MeasureAllFiltersRequest(routeId string, start time.Time)
	MeasureBackend(routeId string, start time.Time)
	MeasureBackendHost(routeBackendHost string, start time.Time)
	MeasureFilterResponse(filterName string, start time.Time)
	MeasureAllFiltersResponse(routeId string, start time.Time)
	MeasureResponse(code int, method string, routeId string, start time.Time)
	MeasureServe(routeId, host, method string, code int, start time.Time)
	IncRoutingFailures()
	IncErrorsBackend(routeId string)
	MeasureBackend5xx(t time.Time)
	IncErrorsStreaming(routeId string)
	RegisterHandler(path string, handler *http.ServeMux)
	UpdateGauge(key string, value float64)
}

Metrics is the generic interface that all the required backends should implement to be an skipper metrics compatible backend.

var (
	Default Metrics
	Void    Metrics
)

func NewMetrics added in v0.10.234

func NewMetrics(o Options) Metrics

NewMetrics creates a metrics collector instance based on the Format option.

type Options

type Options struct {
	// the metrics exposing format.
	Format Kind

	// Common prefix for the keys of the different
	// collected metrics.
	Prefix string

	// If set, garbage collector metrics are collected
	// in addition to the http traffic metrics.
	EnableDebugGcMetrics bool

	// If set, Go runtime metrics are collected in
	// addition to the http traffic metrics.
	EnableRuntimeMetrics bool

	// If set, detailed total response time metrics will be collected
	// for each route, additionally grouped by status and method.
	EnableServeRouteMetrics bool

	// If set, a counter for each route is generated, additionally
	// grouped by status and method. It differs from the automatically
	// generated counter from `EnableServeRouteMetrics` because it will
	// always contain the status and method labels, independently of the
	// `EnableServeMethodMetric` and `EnableServeStatusCodeMetric`
	// flags.
	EnableServeRouteCounter bool

	// If set, detailed total response time metrics will be collected
	// for each host, additionally grouped by status and method.
	EnableServeHostMetrics bool

	// If set, a counter for each host is generated, additionally
	// grouped by status and method. It differs from the automatically
	// generated counter from `EnableServeHostMetrics` because it will
	// always contain the status and method labels, independently of the
	// `EnableServeMethodMetric` and `EnableServeStatusCodeMetric` flags.
	EnableServeHostCounter bool

	// If set, the detailed total response time metrics will contain the
	// HTTP method as a domain of the metric. It affects both route and
	// host splitted metrics.
	EnableServeMethodMetric bool

	// If set, the detailed total response time metrics will contain the
	// HTTP Response status code as a domain of the metric. It affects
	// both route and host splitted metrics.
	EnableServeStatusCodeMetric bool

	// If set, detailed response time metrics will be collected
	// for each backend host
	EnableBackendHostMetrics bool

	// EnableAllFiltersMetrics enables collecting combined filter
	// metrics per each route. Without the DisableCompatibilityDefaults,
	// it is enabled by default.
	EnableAllFiltersMetrics bool

	// EnableCombinedResponseMetrics enables collecting response time
	// metrics combined for every route.
	EnableCombinedResponseMetrics bool

	// EnableRouteResponseMetrics enables collecting response time
	// metrics per each route. Without the DisableCompatibilityDefaults,
	// it is enabled by default.
	EnableRouteResponseMetrics bool

	// EnableRouteBackendErrorsCounters enables counters for backend
	// errors per each route. Without the DisableCompatibilityDefaults,
	// it is enabled by default.
	EnableRouteBackendErrorsCounters bool

	// EnableRouteStreamingErrorsCounters enables counters for streaming
	// errors per each route. Without the DisableCompatibilityDefaults,
	// it is enabled by default.
	EnableRouteStreamingErrorsCounters bool

	// EnableRouteBackendMetrics enables backend response time metrics
	// per each route. Without the DisableCompatibilityDefaults, it is
	// enabled by default.
	EnableRouteBackendMetrics bool

	// UseExpDecaySample, when set, makes the histograms use an exponentially
	// decaying sample instead of the default uniform one.
	UseExpDecaySample bool

	// HistogramBuckets defines buckets into which the observations are counted for
	// histogram metrics.
	HistogramBuckets []float64

	// The following options, for backwards compatibility, are true
	// by default: EnableAllFiltersMetrics, EnableRouteResponseMetrics,
	// EnableRouteBackendErrorsCounters, EnableRouteStreamingErrorsCounters,
	// EnableRouteBackendMetrics. With this compatibility flag, the default
	// for these options can be set to false.
	DisableCompatibilityDefaults bool

	// EnableProfile exposes profiling information on /pprof of the
	// metrics listener.
	EnableProfile bool

	// BlockProfileRate calls runtime.SetBlockProfileRate(BlockProfileRate) if != 0 (<0 will disable) and profiling is enabled
	BlockProfileRate int

	// MutexProfileFraction calls runtime.SetMutexProfileFraction(MutexProfileFraction) if != 0 (<0 will disable) and profiling is enabled
	MutexProfileFraction int

	// MemProfileRate calls runtime.SetMemProfileRate(MemProfileRate) if != 0 (<0 will disable) and profiling is enabled
	MemProfileRate int

	// An instance of a Prometheus registry. It allows registering and serving custom metrics when skipper is used as a
	// library.
	// A new registry is created if this option is nil.
	PrometheusRegistry *prometheus.Registry
}

Options for initializing metrics collection.

type Prometheus added in v0.9.141

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

Prometheus implements the prometheus metrics backend.

func NewPrometheus added in v0.9.141

func NewPrometheus(opts Options) *Prometheus

NewPrometheus returns a new Prometheus metric backend.

func (*Prometheus) CreateHandler added in v0.9.169

func (p *Prometheus) CreateHandler() http.Handler

func (*Prometheus) IncCounter added in v0.9.141

func (p *Prometheus) IncCounter(key string)

IncCounter satisfies Metrics interface.

func (*Prometheus) IncCounterBy added in v0.10.113

func (p *Prometheus) IncCounterBy(key string, value int64)

IncCounterBy satisfies Metrics interface.

func (*Prometheus) IncErrorsBackend added in v0.9.141

func (p *Prometheus) IncErrorsBackend(routeID string)

IncErrorsBackend satisfies Metrics interface.

func (*Prometheus) IncErrorsStreaming added in v0.9.141

func (p *Prometheus) IncErrorsStreaming(routeID string)

IncErrorsStreaming satisfies Metrics interface.

func (*Prometheus) IncFloatCounterBy added in v0.10.153

func (p *Prometheus) IncFloatCounterBy(key string, value float64)

IncFloatCounterBy satisfies Metrics interface.

func (*Prometheus) IncRoutingFailures added in v0.9.141

func (p *Prometheus) IncRoutingFailures()

IncRoutingFailures satisfies Metrics interface.

func (*Prometheus) MeasureAllFiltersRequest added in v0.9.141

func (p *Prometheus) MeasureAllFiltersRequest(routeID string, start time.Time)

MeasureAllFiltersRequest satisfies Metrics interface.

func (*Prometheus) MeasureAllFiltersResponse added in v0.9.141

func (p *Prometheus) MeasureAllFiltersResponse(routeID string, start time.Time)

MeasureAllFiltersResponse satisfies Metrics interface.

func (*Prometheus) MeasureBackend added in v0.9.141

func (p *Prometheus) MeasureBackend(routeID string, start time.Time)

MeasureBackend satisfies Metrics interface.

func (*Prometheus) MeasureBackend5xx added in v0.9.141

func (p *Prometheus) MeasureBackend5xx(start time.Time)

MeasureBackend5xx satisfies Metrics interface.

func (*Prometheus) MeasureBackendHost added in v0.9.141

func (p *Prometheus) MeasureBackendHost(routeBackendHost string, start time.Time)

MeasureBackendHost satisfies Metrics interface.

func (*Prometheus) MeasureFilterRequest added in v0.9.141

func (p *Prometheus) MeasureFilterRequest(filterName string, start time.Time)

MeasureFilterRequest satisfies Metrics interface.

func (*Prometheus) MeasureFilterResponse added in v0.9.141

func (p *Prometheus) MeasureFilterResponse(filterName string, start time.Time)

MeasureFilterResponse satisfies Metrics interface.

func (*Prometheus) MeasureResponse added in v0.9.141

func (p *Prometheus) MeasureResponse(code int, method string, routeID string, start time.Time)

MeasureResponse satisfies Metrics interface.

func (*Prometheus) MeasureRouteLookup added in v0.9.141

func (p *Prometheus) MeasureRouteLookup(start time.Time)

MeasureRouteLookup satisfies Metrics interface.

func (*Prometheus) MeasureServe added in v0.9.141

func (p *Prometheus) MeasureServe(routeID, host, method string, code int, start time.Time)

MeasureServe satisfies Metrics interface.

func (*Prometheus) MeasureSince added in v0.9.141

func (p *Prometheus) MeasureSince(key string, start time.Time)

MeasureSince satisfies Metrics interface.

func (*Prometheus) RegisterHandler added in v0.9.141

func (p *Prometheus) RegisterHandler(path string, mux *http.ServeMux)

RegisterHandler satisfies Metrics interface.

func (*Prometheus) UpdateGauge added in v0.10.59

func (p *Prometheus) UpdateGauge(key string, v float64)

UpdateGauge satisfies Metrics interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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