metrics

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2018 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package metrics contains a type for aggregating and propagating metrics to various services based on configuration.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidMetricOutputType = errors.New("invalid metrics output type")
)

Errors for the metrics package.

View Source
var (
	ErrTimedOut = errors.New("timed out")
)

Errors for the HTTP type.

Functions

func Descriptions

func Descriptions() string

Descriptions returns a formatted string of collated descriptions of each type.

func SanitiseConfig

func SanitiseConfig(conf Config) (interface{}, error)

SanitiseConfig returns a sanitised version of the Config, meaning sections that aren't relevant to behaviour are removed.

Types

type Config

type Config struct {
	Type       string       `json:"type" yaml:"type"`
	Prefix     string       `json:"prefix" yaml:"prefix"`
	HTTP       struct{}     `json:"http_server" yaml:"http_server"`
	Prometheus struct{}     `json:"prometheus" yaml:"prometheus"`
	Statsd     StatsdConfig `json:"statsd" yaml:"statsd"`
}

Config is the all encompassing configuration struct for all metric output types.

func NewConfig

func NewConfig() Config

NewConfig returns a configuration struct fully populated with default values.

type DudStat

type DudStat struct{}

DudStat implements the Stat interface but doesn't actual do anything.

func (DudStat) Decr

func (d DudStat) Decr(count int64) error

Decr does nothing.

func (DudStat) Gauge

func (d DudStat) Gauge(value int64) error

Gauge does nothing.

func (DudStat) Incr

func (d DudStat) Incr(count int64) error

Incr does nothing.

func (DudStat) Timing

func (d DudStat) Timing(delta int64) error

Timing does nothing.

type DudType

type DudType struct{}

DudType implements the Type interface but doesn't actual do anything.

func (DudType) Close

func (d DudType) Close() error

Close does nothing.

func (DudType) Decr

func (d DudType) Decr(path string, count int64) error

Decr does nothing.

func (DudType) Gauge

func (d DudType) Gauge(path string, value int64) error

Gauge does nothing.

func (DudType) GetCounter

func (d DudType) GetCounter(path ...string) StatCounter

GetCounter returns a DudStat.

func (DudType) GetGauge

func (d DudType) GetGauge(path ...string) StatGauge

GetGauge returns a DudStat.

func (DudType) GetTimer

func (d DudType) GetTimer(path ...string) StatTimer

GetTimer returns a DudStat.

func (DudType) Incr

func (d DudType) Incr(path string, count int64) error

Incr does nothing.

func (DudType) Timing

func (d DudType) Timing(path string, delta int64) error

Timing does nothing.

type HTTP

type HTTP struct {
	sync.Mutex
	// contains filtered or unexported fields
}

HTTP is an object with capability to hold internal stats as a JSON endpoint.

func (*HTTP) Close

func (h *HTTP) Close() error

Close stops the HTTP object from aggregating metrics and cleans up resources.

func (*HTTP) Decr

func (h *HTTP) Decr(stat string, value int64) error

Decr decrements a stat by a value.

func (*HTTP) Gauge

func (h *HTTP) Gauge(stat string, value int64) error

Gauge sets a stat as a gauge value.

func (*HTTP) GetCounter

func (h *HTTP) GetCounter(path ...string) StatCounter

GetCounter returns a stat counter object for a path.

func (*HTTP) GetGauge

func (h *HTTP) GetGauge(path ...string) StatGauge

GetGauge returns a stat gauge object for a path.

func (*HTTP) GetTimer

func (h *HTTP) GetTimer(path ...string) StatTimer

GetTimer returns a stat timer object for a path.

func (*HTTP) HandlerFunc

func (h *HTTP) HandlerFunc() http.HandlerFunc

HandlerFunc returns an http.HandlerFunc for accessing metrics as a JSON blob.

func (*HTTP) Incr

func (h *HTTP) Incr(stat string, value int64) error

Incr increments a stat by a value.

func (*HTTP) Timing

func (h *HTTP) Timing(stat string, delta int64) error

Timing sets a stat representing a duration.

type HTTPStat

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

HTTPStat is a representation of a single metric stat. Interactions with this stat are thread safe.

func (*HTTPStat) Decr

func (h *HTTPStat) Decr(count int64) error

Decr decrements a metric by an amount.

func (*HTTPStat) Gauge

func (h *HTTPStat) Gauge(value int64) error

Gauge sets a gauge metric.

func (*HTTPStat) Incr

func (h *HTTPStat) Incr(count int64) error

Incr increments a metric by an amount.

func (*HTTPStat) Timing

func (h *HTTPStat) Timing(delta int64) error

Timing sets a timing metric.

type PromGauge

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

PromGauge is a representation of a single metric stat. Interactions with this stat are thread safe.

func (*PromGauge) Decr

func (p *PromGauge) Decr(count int64) error

Decr decrements a metric by an amount.

func (*PromGauge) Gauge

func (p *PromGauge) Gauge(value int64) error

Gauge sets a gauge metric.

func (*PromGauge) Incr

func (p *PromGauge) Incr(count int64) error

Incr increments a metric by an amount.

type PromTiming

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

PromTiming is a representation of a single metric stat. Interactions with this stat are thread safe.

func (*PromTiming) Timing

func (p *PromTiming) Timing(val int64) error

Timing sets a timing metric.

type Prometheus

type Prometheus struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Prometheus is a stats object with capability to hold internal stats as a JSON endpoint.

func (*Prometheus) Close

func (p *Prometheus) Close() error

Close stops the Prometheus object from aggregating metrics and cleans up resources.

func (*Prometheus) Decr

func (p *Prometheus) Decr(stat string, value int64) error

Decr decrements a stat by a value.

func (*Prometheus) Gauge

func (p *Prometheus) Gauge(stat string, value int64) error

Gauge sets a stat as a gauge value.

func (*Prometheus) GetCounter

func (p *Prometheus) GetCounter(path ...string) StatCounter

GetCounter returns a stat counter object for a path.

func (*Prometheus) GetGauge

func (p *Prometheus) GetGauge(path ...string) StatGauge

GetGauge returns a stat gauge object for a path.

func (*Prometheus) GetTimer

func (p *Prometheus) GetTimer(path ...string) StatTimer

GetTimer returns a stat timer object for a path.

func (*Prometheus) HandlerFunc

func (p *Prometheus) HandlerFunc() http.HandlerFunc

HandlerFunc returns an http.HandlerFunc for scraping metrics.

func (*Prometheus) Incr

func (p *Prometheus) Incr(stat string, value int64) error

Incr increments a stat by a value.

func (*Prometheus) Timing

func (p *Prometheus) Timing(stat string, delta int64) error

Timing sets a stat representing a duration.

type PrometheusConfig

type PrometheusConfig struct {
}

PrometheusConfig is config for the Prometheus metrics type.

func NewPrometheusConfig

func NewPrometheusConfig() PrometheusConfig

NewPrometheusConfig creates an PrometheusConfig struct with default values.

type StatCounter

type StatCounter interface {
	// Incr increments a metric by an amount.
	Incr(count int64) error

	// Decr decrements a metric by an amount.
	Decr(count int64) error
}

StatCounter is a representation of a single counter metric stat. Interactions with this stat are thread safe.

type StatGauge

type StatGauge interface {
	// Gauge sets a gauge metric.
	Gauge(value int64) error
}

StatGauge is a representation of a single gauge metric stat. Interactions with this stat are thread safe.

type StatTimer

type StatTimer interface {
	// Timing sets a timing metric.
	Timing(delta int64) error
}

StatTimer is a representation of a single timer metric stat. Interactions with this stat are thread safe.

type Statsd

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

Statsd is a stats object with capability to hold internal stats as a JSON endpoint.

func (*Statsd) Close

func (h *Statsd) Close() error

Close stops the Statsd object from aggregating metrics and cleans up resources.

func (*Statsd) Decr

func (h *Statsd) Decr(stat string, value int64) error

Decr decrements a stat by a value.

func (*Statsd) Gauge

func (h *Statsd) Gauge(stat string, value int64) error

Gauge sets a stat as a gauge value.

func (*Statsd) GetCounter

func (h *Statsd) GetCounter(path ...string) StatCounter

GetCounter returns a stat counter object for a path.

func (*Statsd) GetGauge

func (h *Statsd) GetGauge(path ...string) StatGauge

GetGauge returns a stat gauge object for a path.

func (*Statsd) GetTimer

func (h *Statsd) GetTimer(path ...string) StatTimer

GetTimer returns a stat timer object for a path.

func (*Statsd) Incr

func (h *Statsd) Incr(stat string, value int64) error

Incr increments a stat by a value.

func (*Statsd) Timing

func (h *Statsd) Timing(stat string, delta int64) error

Timing sets a stat representing a duration.

type StatsdConfig

type StatsdConfig struct {
	Address       string `json:"address" yaml:"address"`
	FlushPeriod   string `json:"flush_period" yaml:"flush_period"`
	MaxPacketSize int    `json:"max_packet_size" yaml:"max_packet_size"`
	Network       string `json:"network" yaml:"network"`
}

StatsdConfig is config for the Statsd metrics type.

func NewStatsdConfig

func NewStatsdConfig() StatsdConfig

NewStatsdConfig creates an StatsdConfig struct with default values.

type StatsdStat

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

StatsdStat is a representation of a single metric stat. Interactions with this stat are thread safe.

func (*StatsdStat) Decr

func (s *StatsdStat) Decr(count int64) error

Decr decrements a metric by an amount.

func (*StatsdStat) Gauge

func (s *StatsdStat) Gauge(value int64) error

Gauge sets a gauge metric.

func (*StatsdStat) Incr

func (s *StatsdStat) Incr(count int64) error

Incr increments a metric by an amount.

func (*StatsdStat) Timing

func (s *StatsdStat) Timing(delta int64) error

Timing sets a timing metric.

type Type

type Type interface {
	// GetCounter returns an editable counter stat for a given path.
	GetCounter(path ...string) StatCounter

	// GetTimer returns an editable timer stat for a given path.
	GetTimer(path ...string) StatTimer

	// GetGauge returns an editable gauge stat for a given path.
	GetGauge(path ...string) StatGauge

	// Incr increments a metric by an amount.
	Incr(path string, count int64) error

	// Decr decrements a metric by an amount.
	Decr(path string, count int64) error

	// Timing sets a timing metric.
	Timing(path string, delta int64) error

	// Gauge sets a gauge metric.
	Gauge(path string, value int64) error

	// Close stops aggregating stats and clean up resources.
	Close() error
}

Type is an interface for metrics aggregation.

func Namespaced

func Namespaced(t Type, ns string) Type

Namespaced embeds an existing metrics aggregator under a new namespace. The prefix of the embedded aggregator is still the ultimate prefix of metrics.

func New

func New(conf Config) (Type, error)

New creates a metric output type based on a configuration.

func NewHTTP

func NewHTTP(config Config) (Type, error)

NewHTTP creates and returns a new HTTP object.

func NewPrometheus

func NewPrometheus(config Config) (Type, error)

NewPrometheus creates and returns a new Prometheus object.

func NewStatsd

func NewStatsd(config Config) (Type, error)

NewStatsd creates and returns a new Statsd object.

type WithHandlerFunc

type WithHandlerFunc interface {
	HandlerFunc() http.HandlerFunc
}

WithHandlerFunc is an interface for metrics types that can expose their metrics through an HTTP HandlerFunc endpoint. If a Type can be cast into WithHandlerFunc then you should register its endpoint to the an HTTP server.

Jump to

Keyboard shortcuts

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