metrics

package
v0.9.150 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2018 License: Apache-2.0, MIT Imports: 11 Imported by: 0

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"
	KeyServeRoute                 = "serveroute.%s.%s.%d"
	KeyServeHost                  = "servehost.%s.%s.%d"
	Key5xxsBackend                = "all.backend.5xx"

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

Variables

This section is empty.

Functions

func NewDefaultHandler added in v0.9.132

func NewDefaultHandler(o Options) http.Handler

NewDefaultHandler returns a default metrics handler.

func NewHandler added in v0.9.61

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

NewHandler returns a collection of metrics handlers.

Types

type CodaHale added in v0.9.132

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.132

func NewCodaHale(o Options) *CodaHale

NewCodaHale returns a new CodaHale backend of metrics.

func NewVoid

func NewVoid() *CodaHale

func (*CodaHale) IncCounter added in v0.9.132

func (c *CodaHale) IncCounter(key string)

func (*CodaHale) IncErrorsBackend added in v0.9.132

func (c *CodaHale) IncErrorsBackend(routeId string)

func (*CodaHale) IncErrorsStreaming added in v0.9.132

func (c *CodaHale) IncErrorsStreaming(routeId string)

func (*CodaHale) IncRoutingFailures added in v0.9.132

func (c *CodaHale) IncRoutingFailures()

func (*CodaHale) MeasureAllFiltersRequest added in v0.9.132

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

func (*CodaHale) MeasureAllFiltersResponse added in v0.9.132

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

func (*CodaHale) MeasureBackend added in v0.9.132

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

func (*CodaHale) MeasureBackend5xx added in v0.9.132

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

func (*CodaHale) MeasureBackendHost added in v0.9.132

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

func (*CodaHale) MeasureFilterRequest added in v0.9.132

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

func (*CodaHale) MeasureFilterResponse added in v0.9.132

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

func (*CodaHale) MeasureResponse added in v0.9.132

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

func (*CodaHale) MeasureRouteLookup added in v0.9.132

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

func (*CodaHale) MeasureServe added in v0.9.132

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

func (*CodaHale) MeasureSince added in v0.9.132

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

func (*CodaHale) RegisterHandler added in v0.9.132

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

type Kind added in v0.9.132

type Kind int

Kind is the type a metrics expose backend can be.

const (
	UnkownKind Kind = iota
	CodaHaleKind
	PrometheusKind
)

func ParseMetricsKind added in v0.9.132

func ParseMetricsKind(t string) Kind

ParseMetricsKind parses an string and returns the correct Metrics kind.

func (Kind) String added in v0.9.132

func (k Kind) String() string

type Metrics

type Metrics interface {
	MeasureSince(key string, start time.Time)
	IncCounter(key string)
	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)
}

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

var (
	Default Metrics
	Void    Metrics
)

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, detailed total response time metrics will be collected
	// for each host, additionally grouped by status and method.
	EnableServeHostMetrics 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

	// 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
}

Options for initializing metrics collection.

type Prometheus added in v0.9.132

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

Prometheus implements the prometheus metrics backend.

func NewPrometheus added in v0.9.132

func NewPrometheus(opts Options) *Prometheus

NewPrometheus returns a new Prometheus metric backend.

func (*Prometheus) IncCounter added in v0.9.132

func (p *Prometheus) IncCounter(key string)

IncCounter satisfies Metrics interface.

func (*Prometheus) IncErrorsBackend added in v0.9.132

func (p *Prometheus) IncErrorsBackend(routeID string)

IncErrorsBackend satisfies Metrics interface.

func (*Prometheus) IncErrorsStreaming added in v0.9.132

func (p *Prometheus) IncErrorsStreaming(routeID string)

IncErrorsStreaming satisfies Metrics interface.

func (*Prometheus) IncRoutingFailures added in v0.9.132

func (p *Prometheus) IncRoutingFailures()

IncRoutingFailures satisfies Metrics interface.

func (*Prometheus) MeasureAllFiltersRequest added in v0.9.132

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

MeasureAllFiltersRequest satisfies Metrics interface.

func (*Prometheus) MeasureAllFiltersResponse added in v0.9.132

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

MeasureAllFiltersResponse satisfies Metrics interface.

func (*Prometheus) MeasureBackend added in v0.9.132

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

MeasureBackend satisfies Metrics interface.

func (*Prometheus) MeasureBackend5xx added in v0.9.132

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

MeasureBackend5xx satisfies Metrics interface.

func (*Prometheus) MeasureBackendHost added in v0.9.132

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

MeasureBackendHost satisfies Metrics interface.

func (*Prometheus) MeasureFilterRequest added in v0.9.132

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

MeasureFilterRequest satisfies Metrics interface.

func (*Prometheus) MeasureFilterResponse added in v0.9.132

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

MeasureFilterResponse satisfies Metrics interface.

func (*Prometheus) MeasureResponse added in v0.9.132

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

MeasureResponse satisfies Metrics interface.

func (*Prometheus) MeasureRouteLookup added in v0.9.132

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

MeasureRouteLookup satisfies Metrics interface.

func (*Prometheus) MeasureServe added in v0.9.132

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

MeasureServe satisfies Metrics interface.

func (*Prometheus) MeasureSince added in v0.9.132

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

MeasureSince satisfies Metrics interface.

func (*Prometheus) RegisterHandler added in v0.9.132

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

RegisterHandler satisfies Metrics interface.

Jump to

Keyboard shortcuts

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