metrics

package module
v0.0.0-...-f563c51 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

README

KrakenD metrics

A set of building blocks for instrumenting KrakenD gateways

Available middlewares

There are the avaliable middlewares to add to the KrakenD pipes.

  1. Backend
  2. Proxy
  3. Router

Available router flavours

  1. mux Mux based routers and handlers
  2. gin Gin based routers and handlers

Check the examples and the documentation for more details

Configuration

You need to add an ExtraConfig section to the configuration to enable the metrics collector (an empty one will use the defaults).

You can disable metrics by layer by explicitly setting it to true (the default is to be enabled):

  • backend_disabled bool
  • proxy_disabled bool
  • router_disabled bool

Or configure the collection time of metrics:

  • collection_time (default: 60s) (Ex: "30s", "5m", "500ms", ...)
Configuration Example

This configuration will set the collection time to 2 minutes and will disable the proxy metrics collector (backend and router metrics will be enabled since the default for all layers is to be enabled).

  "extra_config": {
    "github_com/devopsfaith/krakend-metrics": {
      "collection_time": "2m",
      "proxy_disabled": true,
    }
  }

or leave the defaults:

"extra_config": {
  github_com/devopsfaith/krakend-metrics": {}
}

Documentation

Overview

Package metrics defines a set of basic building blocks for instrumenting KrakenD gateways

Check the "github.com/devopsfaith/krakend-metrics/gin" and "github.com/devopsfaith/krakend-metrics/mux" packages for complete implementations

Index

Constants

View Source
const Namespace = "github_com/devopsfaith/krakend-metrics"

Namespace is the key to look for extra configuration details

Variables

This section is empty.

Functions

func ConfigGetter

func ConfigGetter(e config.ExtraConfig) interface{}

ConfigGetter implements the config.ConfigGetter interface. It parses the extra config for the collectors and returns a defaultCfg if something goes wrong.

func NewDummyRegistry

func NewDummyRegistry() metrics.Registry

func NewProxyMiddleware

func NewProxyMiddleware(layer, name string, pm *ProxyMetrics) proxy.Middleware

NewProxyMiddleware creates a proxy middleware ready to be injected in the pipe as instrumentation point

Types

type Config

type Config struct {
	ProxyDisabled    bool
	RouterDisabled   bool
	BackendDisabled  bool
	CollectionTime   time.Duration
	ListenAddr       string
	EndpointDisabled bool
}

Config holds if a component is active or not

type DummyRegistry

type DummyRegistry struct{}

DummyRegistry implements the rcrowley/go-metrics.Registry interface

func (DummyRegistry) Each

func (r DummyRegistry) Each(_ func(string, interface{}))

func (DummyRegistry) Get

func (r DummyRegistry) Get(_ string) interface{}

func (DummyRegistry) GetAll

func (r DummyRegistry) GetAll() map[string]map[string]interface{}

func (DummyRegistry) GetOrRegister

func (r DummyRegistry) GetOrRegister(_ string, i interface{}) interface{}

func (DummyRegistry) Register

func (r DummyRegistry) Register(_ string, _ interface{}) error

func (DummyRegistry) RunHealthchecks

func (r DummyRegistry) RunHealthchecks()

func (DummyRegistry) Unregister

func (r DummyRegistry) Unregister(_ string)

func (DummyRegistry) UnregisterAll

func (r DummyRegistry) UnregisterAll()

type HistogramData

type HistogramData struct {
	Max         int64
	Min         int64
	Mean        float64
	Stddev      float64
	Variance    float64
	Percentiles []float64
}

HistogramData is a snapshot of an actual histogram

type Metrics

type Metrics struct {
	// Config is the metrics collector configuration
	Config *Config
	// Proxy is the metrics collector for the proxy package
	Proxy *ProxyMetrics
	// Router is the metrics collector for the router package
	Router *RouterMetrics
	// Registry is the metrics register
	Registry *metrics.Registry
	// contains filtered or unexported fields
}

Metrics is the component that manages all the metrics

func New

New creates a new metrics producer

func (*Metrics) BackendFactory

func (m *Metrics) BackendFactory(segmentName string, next proxy.BackendFactory) proxy.BackendFactory

BackendFactory creates an instrumented backend factory

func (*Metrics) DefaultBackendFactory

func (m *Metrics) DefaultBackendFactory() proxy.BackendFactory

DefaultBackendFactory creates an instrumented default HTTP backend factory

func (*Metrics) NewProxyMiddleware

func (m *Metrics) NewProxyMiddleware(layer, name string) proxy.Middleware

NewProxyMiddleware creates a proxy middleware ready to be injected in the pipe as instrumentation point

func (*Metrics) ProxyFactory

func (m *Metrics) ProxyFactory(segmentName string, next proxy.Factory) proxy.FactoryFunc

ProxyFactory creates an instrumented proxy factory

func (*Metrics) Snapshot

func (m *Metrics) Snapshot() Stats

Snapshot returns the last calculted snapshot

func (*Metrics) TakeSnapshot

func (m *Metrics) TakeSnapshot() Stats

TakeSnapshot takes a snapshot of the current state

type ProxyMetrics

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

ProxyMetrics is the metrics collector for the proxy package

func NewProxyMetrics

func NewProxyMetrics(parent *metrics.Registry) *ProxyMetrics

NewProxyMetrics creates a ProxyMetrics using the injected registry

func (*ProxyMetrics) Counter

func (rm *ProxyMetrics) Counter(labels ...string) metrics.Counter

Counter gets or register a counter

func (*ProxyMetrics) Histogram

func (rm *ProxyMetrics) Histogram(labels ...string) metrics.Histogram

Histogram gets or register a histogram

type RouterMetrics

type RouterMetrics struct {
	ProxyMetrics
	// contains filtered or unexported fields
}

RouterMetrics is the metrics collector for the router package

func NewRouterMetrics

func NewRouterMetrics(parent *metrics.Registry) *RouterMetrics

NewRouterMetrics creates a RouterMetrics using the injected registry

func (*RouterMetrics) Aggregate

func (rm *RouterMetrics) Aggregate()

func (*RouterMetrics) Connection

func (rm *RouterMetrics) Connection()

Connection adds one to the internal connected counter

func (*RouterMetrics) Disconnection

func (rm *RouterMetrics) Disconnection()

Disconnection adds one to the internal disconnected counter

func (*RouterMetrics) RegisterResponseWriterMetrics

func (rm *RouterMetrics) RegisterResponseWriterMetrics(name string)

type Stats

type Stats struct {
	Time       int64
	Counters   map[string]int64
	Gauges     map[string]int64
	Histograms map[string]HistogramData
}

Stats represents a snapshot of the collected metrics

func NewStats

func NewStats() Stats

NewStats instantiates a stats struct

Directories

Path Synopsis
Package gin defines a set of basic building blocks for instrumenting KrakenD gateways built using the gin router
Package gin defines a set of basic building blocks for instrumenting KrakenD gateways built using the gin router
Package mux defines a set of basic building blocks for instrumenting KrakenD gateways built using the mux router
Package mux defines a set of basic building blocks for instrumenting KrakenD gateways built using the mux router

Jump to

Keyboard shortcuts

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