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

func NewDefaultHandler(o Options) http.Handler

    NewDefaultHandler returns a default metrics handler.

    func NewHandler

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

      NewHandler returns a collection of metrics handlers.

      Types

      type All

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

      func NewAll

      func NewAll(o Options) *All

      func (*All) IncCounter

      func (a *All) IncCounter(key string)

      func (*All) IncCounterBy

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

      func (*All) IncErrorsBackend

      func (a *All) IncErrorsBackend(routeId string)

      func (*All) IncErrorsStreaming

      func (a *All) IncErrorsStreaming(routeId string)

      func (*All) IncFloatCounterBy

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

      func (*All) IncRoutingFailures

      func (a *All) IncRoutingFailures()

      func (*All) MeasureAllFiltersRequest

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

      func (*All) MeasureAllFiltersResponse

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

      func (*All) MeasureBackend

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

      func (*All) MeasureBackend5xx

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

      func (*All) MeasureBackendHost

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

      func (*All) MeasureFilterRequest

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

      func (*All) MeasureFilterResponse

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

      func (*All) MeasureResponse

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

      func (*All) MeasureRouteLookup

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

      func (*All) MeasureServe

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

      func (*All) MeasureSince

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

      func (*All) RegisterHandler

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

      func (*All) UpdateGauge

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

      type CodaHale

      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

        func NewCodaHale(o Options) *CodaHale

          NewCodaHale returns a new CodaHale backend of metrics.

          func NewVoid

          func NewVoid() *CodaHale

          func (*CodaHale) CreateHandler

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

          func (*CodaHale) IncCounter

          func (c *CodaHale) IncCounter(key string)

          func (*CodaHale) IncCounterBy

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

          func (*CodaHale) IncErrorsBackend

          func (c *CodaHale) IncErrorsBackend(routeId string)

          func (*CodaHale) IncErrorsStreaming

          func (c *CodaHale) IncErrorsStreaming(routeId string)

          func (*CodaHale) IncFloatCounterBy

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

          func (*CodaHale) IncRoutingFailures

          func (c *CodaHale) IncRoutingFailures()

          func (*CodaHale) MeasureAllFiltersRequest

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

          func (*CodaHale) MeasureAllFiltersResponse

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

          func (*CodaHale) MeasureBackend

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

          func (*CodaHale) MeasureBackend5xx

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

          func (*CodaHale) MeasureBackendHost

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

          func (*CodaHale) MeasureFilterRequest

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

          func (*CodaHale) MeasureFilterResponse

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

          func (*CodaHale) MeasureResponse

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

          func (*CodaHale) MeasureRouteLookup

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

          func (*CodaHale) MeasureServe

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

          func (*CodaHale) MeasureSince

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

          func (*CodaHale) RegisterHandler

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

          func (*CodaHale) UpdateGauge

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

          type Kind

          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

            func ParseMetricsKind(t string) Kind

              ParseMetricsKind parses an string and returns the correct Metrics kind.

              func (Kind) String

              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

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

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

                      Prometheus implements the prometheus metrics backend.

                      func NewPrometheus

                      func NewPrometheus(opts Options) *Prometheus

                        NewPrometheus returns a new Prometheus metric backend.

                        func (*Prometheus) CreateHandler

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

                        func (*Prometheus) IncCounter

                        func (p *Prometheus) IncCounter(key string)

                          IncCounter satisfies Metrics interface.

                          func (*Prometheus) IncCounterBy

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

                            IncCounterBy satisfies Metrics interface.

                            func (*Prometheus) IncErrorsBackend

                            func (p *Prometheus) IncErrorsBackend(routeID string)

                              IncErrorsBackend satisfies Metrics interface.

                              func (*Prometheus) IncErrorsStreaming

                              func (p *Prometheus) IncErrorsStreaming(routeID string)

                                IncErrorsStreaming satisfies Metrics interface.

                                func (*Prometheus) IncFloatCounterBy

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

                                  IncFloatCounterBy satisfies Metrics interface.

                                  func (*Prometheus) IncRoutingFailures

                                  func (p *Prometheus) IncRoutingFailures()

                                    IncRoutingFailures satisfies Metrics interface.

                                    func (*Prometheus) MeasureAllFiltersRequest

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

                                      MeasureAllFiltersRequest satisfies Metrics interface.

                                      func (*Prometheus) MeasureAllFiltersResponse

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

                                        MeasureAllFiltersResponse satisfies Metrics interface.

                                        func (*Prometheus) MeasureBackend

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

                                          MeasureBackend satisfies Metrics interface.

                                          func (*Prometheus) MeasureBackend5xx

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

                                            MeasureBackend5xx satisfies Metrics interface.

                                            func (*Prometheus) MeasureBackendHost

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

                                              MeasureBackendHost satisfies Metrics interface.

                                              func (*Prometheus) MeasureFilterRequest

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

                                                MeasureFilterRequest satisfies Metrics interface.

                                                func (*Prometheus) MeasureFilterResponse

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

                                                  MeasureFilterResponse satisfies Metrics interface.

                                                  func (*Prometheus) MeasureResponse

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

                                                    MeasureResponse satisfies Metrics interface.

                                                    func (*Prometheus) MeasureRouteLookup

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

                                                      MeasureRouteLookup satisfies Metrics interface.

                                                      func (*Prometheus) MeasureServe

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

                                                        MeasureServe satisfies Metrics interface.

                                                        func (*Prometheus) MeasureSince

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

                                                          MeasureSince satisfies Metrics interface.

                                                          func (*Prometheus) RegisterHandler

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

                                                            RegisterHandler satisfies Metrics interface.

                                                            func (*Prometheus) UpdateGauge

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

                                                              UpdateGauge satisfies Metrics interface.

                                                              Directories

                                                              Path Synopsis