skipper: github.com/zalando/skipper/metrics Index | Files | Directories

package metrics

import "github.com/zalando/skipper/metrics"

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

Package Files

all_kind.go codahale.go doc.go metrics.go prometheus.go utils.go

Constants

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

func NewDefaultHandler Uses

func NewDefaultHandler(o Options) http.Handler

NewDefaultHandler returns a default metrics handler.

func NewHandler Uses

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

NewHandler returns a collection of metrics handlers.

type All Uses

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

func NewAll Uses

func NewAll(o Options) *All

func (*All) IncCounter Uses

func (a *All) IncCounter(key string)

func (*All) IncCounterBy Uses

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

func (*All) IncErrorsBackend Uses

func (a *All) IncErrorsBackend(routeId string)

func (*All) IncErrorsStreaming Uses

func (a *All) IncErrorsStreaming(routeId string)

func (*All) IncFloatCounterBy Uses

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

func (*All) IncRoutingFailures Uses

func (a *All) IncRoutingFailures()

func (*All) MeasureAllFiltersRequest Uses

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

func (*All) MeasureAllFiltersResponse Uses

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

func (*All) MeasureBackend Uses

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

func (*All) MeasureBackend5xx Uses

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

func (*All) MeasureBackendHost Uses

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

func (*All) MeasureFilterRequest Uses

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

func (*All) MeasureFilterResponse Uses

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

func (*All) MeasureResponse Uses

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

func (*All) MeasureRouteLookup Uses

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

func (*All) MeasureServe Uses

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

func (*All) MeasureSince Uses

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

func (*All) RegisterHandler Uses

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

func (*All) UpdateGauge Uses

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

type CodaHale Uses

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 Uses

func NewCodaHale(o Options) *CodaHale

NewCodaHale returns a new CodaHale backend of metrics.

func NewVoid Uses

func NewVoid() *CodaHale

func (*CodaHale) CreateHandler Uses

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

func (*CodaHale) IncCounter Uses

func (c *CodaHale) IncCounter(key string)

func (*CodaHale) IncCounterBy Uses

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

func (*CodaHale) IncErrorsBackend Uses

func (c *CodaHale) IncErrorsBackend(routeId string)

func (*CodaHale) IncErrorsStreaming Uses

func (c *CodaHale) IncErrorsStreaming(routeId string)

func (*CodaHale) IncFloatCounterBy Uses

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

func (*CodaHale) IncRoutingFailures Uses

func (c *CodaHale) IncRoutingFailures()

func (*CodaHale) MeasureAllFiltersRequest Uses

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

func (*CodaHale) MeasureAllFiltersResponse Uses

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

func (*CodaHale) MeasureBackend Uses

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

func (*CodaHale) MeasureBackend5xx Uses

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

func (*CodaHale) MeasureBackendHost Uses

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

func (*CodaHale) MeasureFilterRequest Uses

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

func (*CodaHale) MeasureFilterResponse Uses

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

func (*CodaHale) MeasureResponse Uses

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

func (*CodaHale) MeasureRouteLookup Uses

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

func (*CodaHale) MeasureServe Uses

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

func (*CodaHale) MeasureSince Uses

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

func (*CodaHale) RegisterHandler Uses

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

func (*CodaHale) UpdateGauge Uses

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

type Kind Uses

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 Uses

func ParseMetricsKind(t string) Kind

ParseMetricsKind parses an string and returns the correct Metrics kind.

func (Kind) String Uses

func (k Kind) String() string

type Metrics Uses

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 Uses

func NewMetrics(o Options) Metrics

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

type Options Uses

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

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

Options for initializing metrics collection.

type Prometheus Uses

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

Prometheus implements the prometheus metrics backend.

func NewPrometheus Uses

func NewPrometheus(opts Options) *Prometheus

NewPrometheus returns a new Prometheus metric backend.

func (*Prometheus) CreateHandler Uses

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

func (*Prometheus) IncCounter Uses

func (p *Prometheus) IncCounter(key string)

IncCounter satisfies Metrics interface.

func (*Prometheus) IncCounterBy Uses

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

IncCounterBy satisfies Metrics interface.

func (*Prometheus) IncErrorsBackend Uses

func (p *Prometheus) IncErrorsBackend(routeID string)

IncErrorsBackend satisfies Metrics interface.

func (*Prometheus) IncErrorsStreaming Uses

func (p *Prometheus) IncErrorsStreaming(routeID string)

IncErrorsStreaming satisfies Metrics interface.

func (*Prometheus) IncFloatCounterBy Uses

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

IncFloatCounterBy satisfies Metrics interface.

func (*Prometheus) IncRoutingFailures Uses

func (p *Prometheus) IncRoutingFailures()

IncRoutingFailures satisfies Metrics interface.

func (*Prometheus) MeasureAllFiltersRequest Uses

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

MeasureAllFiltersRequest satisfies Metrics interface.

func (*Prometheus) MeasureAllFiltersResponse Uses

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

MeasureAllFiltersResponse satisfies Metrics interface.

func (*Prometheus) MeasureBackend Uses

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

MeasureBackend satisfies Metrics interface.

func (*Prometheus) MeasureBackend5xx Uses

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

MeasureBackend5xx satisfies Metrics interface.

func (*Prometheus) MeasureBackendHost Uses

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

MeasureBackendHost satisfies Metrics interface.

func (*Prometheus) MeasureFilterRequest Uses

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

MeasureFilterRequest satisfies Metrics interface.

func (*Prometheus) MeasureFilterResponse Uses

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

MeasureFilterResponse satisfies Metrics interface.

func (*Prometheus) MeasureResponse Uses

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

MeasureResponse satisfies Metrics interface.

func (*Prometheus) MeasureRouteLookup Uses

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

MeasureRouteLookup satisfies Metrics interface.

func (*Prometheus) MeasureServe Uses

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

MeasureServe satisfies Metrics interface.

func (*Prometheus) MeasureSince Uses

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

MeasureSince satisfies Metrics interface.

func (*Prometheus) RegisterHandler Uses

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

RegisterHandler satisfies Metrics interface.

func (*Prometheus) UpdateGauge Uses

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

UpdateGauge satisfies Metrics interface.

Directories

PathSynopsis
metricstest

Package metrics imports 10 packages (graph) and is imported by 21 packages. Updated 2019-11-09. Refresh now. Tools for package owners.