Documentation ¶
Overview ¶
Package metrics contains a type for aggregating and propagating metrics to various services based on configuration.
Index ¶
- Variables
- func Descriptions() string
- func OptSetLogger(log log.Modular) func(Type)
- func SanitiseConfig(conf Config) (interface{}, error)
- type Config
- type DudStat
- type DudType
- func (d DudType) Close() error
- func (d DudType) Decr(path string, count int64) error
- func (d DudType) Gauge(path string, value int64) error
- func (d DudType) GetCounter(path ...string) StatCounter
- func (d DudType) GetGauge(path ...string) StatGauge
- func (d DudType) GetTimer(path ...string) StatTimer
- func (d DudType) Incr(path string, count int64) error
- func (d DudType) SetLogger(log log.Modular)
- func (d DudType) Timing(path string, delta int64) error
- type Flat
- type FlatStat
- type HTTP
- func (h *HTTP) Close() error
- func (h *HTTP) Decr(stat string, value int64) error
- func (h *HTTP) Gauge(stat string, value int64) error
- func (h *HTTP) GetCounter(path ...string) StatCounter
- func (h *HTTP) GetGauge(path ...string) StatGauge
- func (h *HTTP) GetTimer(path ...string) StatTimer
- func (h *HTTP) HandlerFunc() http.HandlerFunc
- func (h *HTTP) Incr(stat string, value int64) error
- func (h *HTTP) SetLogger(log log.Modular)
- func (h *HTTP) Timing(stat string, delta int64) error
- type Local
- func (l *Local) Close() error
- func (l *Local) Decr(stat string, value int64) error
- func (l *Local) Gauge(stat string, value int64) error
- func (l *Local) GetCounter(path ...string) StatCounter
- func (l *Local) GetCounters() map[string]int64
- func (l *Local) GetGauge(path ...string) StatGauge
- func (l *Local) GetTimer(path ...string) StatTimer
- func (l *Local) GetTimings() map[string]int64
- func (l *Local) Incr(stat string, value int64) error
- func (l *Local) SetLogger(log log.Modular)
- func (l *Local) Timing(stat string, delta int64) error
- type LocalStat
- type PromGauge
- type PromTiming
- type Prometheus
- func (p *Prometheus) Close() error
- func (p *Prometheus) Decr(stat string, value int64) error
- func (p *Prometheus) Gauge(stat string, value int64) error
- func (p *Prometheus) GetCounter(path ...string) StatCounter
- func (p *Prometheus) GetGauge(path ...string) StatGauge
- func (p *Prometheus) GetTimer(path ...string) StatTimer
- func (p *Prometheus) HandlerFunc() http.HandlerFunc
- func (p *Prometheus) Incr(stat string, value int64) error
- func (p *Prometheus) SetLogger(log log.Modular)
- func (p *Prometheus) Timing(stat string, delta int64) error
- type PrometheusConfig
- type StatCounter
- type StatGauge
- type StatTimer
- type Statsd
- func (h *Statsd) Close() error
- func (h *Statsd) Decr(stat string, value int64) error
- func (h *Statsd) Gauge(stat string, value int64) error
- func (h *Statsd) GetCounter(path ...string) StatCounter
- func (h *Statsd) GetGauge(path ...string) StatGauge
- func (h *Statsd) GetTimer(path ...string) StatTimer
- func (h *Statsd) Incr(stat string, value int64) error
- func (h *Statsd) SetLogger(log log.Modular)
- func (h *Statsd) Timing(stat string, delta int64) error
- type StatsdConfig
- type StatsdStat
- type Type
- func Combine(t1, t2 Type) Type
- func Namespaced(t Type, ns string) Type
- func New(conf Config, opts ...func(Type)) (Type, error)
- func NewHTTP(config Config, opts ...func(Type)) (Type, error)
- func NewPrometheus(config Config, opts ...func(Type)) (Type, error)
- func NewStatsd(config Config, opts ...func(Type)) (Type, error)
- func WrapFlat(f Flat) Type
- type WithHandlerFunc
- type WrappedFlat
- func (h *WrappedFlat) Close() error
- func (h *WrappedFlat) Decr(stat string, value int64) error
- func (h *WrappedFlat) Gauge(stat string, value int64) error
- func (h *WrappedFlat) GetCounter(path ...string) StatCounter
- func (h *WrappedFlat) GetGauge(path ...string) StatGauge
- func (h *WrappedFlat) GetTimer(path ...string) StatTimer
- func (h *WrappedFlat) Incr(stat string, value int64) error
- func (h *WrappedFlat) SetLogger(log log.Modular)
- func (h *WrappedFlat) Timing(stat string, delta int64) error
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidMetricOutputType = errors.New("invalid metrics output type")
)
Errors for the metrics package.
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 OptSetLogger ¶
OptSetLogger sets the logging output to be used by the metrics clients.
func SanitiseConfig ¶
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.
type DudStat ¶
type DudStat struct{}
DudStat implements the Stat interface but doesn't actual do anything.
type DudType ¶
type DudType struct {
ID int
}
DudType implements the Type interface but doesn't actual do anything.
func (DudType) GetCounter ¶
func (d DudType) GetCounter(path ...string) StatCounter
GetCounter returns a DudStat.
type Flat ¶
type Flat interface { // 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 cleans up resources. Close() error }
Flat is an interface for setting metrics via flat paths.
type FlatStat ¶
type FlatStat struct {
// contains filtered or unexported fields
}
FlatStat is a representation of a single metric stat. Interactions with this stat are thread safe.
type HTTP ¶
type HTTP struct {
// contains filtered or unexported fields
}
HTTP is an object with capability to hold internal stats as a JSON endpoint.
func (*HTTP) GetCounter ¶
func (h *HTTP) GetCounter(path ...string) StatCounter
GetCounter returns a stat counter 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.
type Local ¶
Local is a metrics aggregator that stores metrics locally.
func (*Local) Close ¶
Close stops the Local object from aggregating metrics and cleans up resources.
func (*Local) GetCounter ¶
func (l *Local) GetCounter(path ...string) StatCounter
GetCounter returns a stat counter object for a path.
func (*Local) GetCounters ¶
GetCounters returns a map of metric paths to counters.
func (*Local) GetTimings ¶
GetTimings returns a map of metric paths to timers.
type LocalStat ¶
type LocalStat struct {
// contains filtered or unexported fields
}
LocalStat is a representation of a single metric stat. Interactions with this stat are thread safe.
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.
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 ¶
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) SetLogger ¶
func (p *Prometheus) SetLogger(log log.Modular)
SetLogger does nothing.
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 ¶
StatGauge is a representation of a single gauge metric stat. Interactions with this stat are thread safe.
type StatTimer ¶
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 ¶
Close stops the Statsd object from aggregating metrics and cleans up resources.
func (*Statsd) GetCounter ¶
func (h *Statsd) GetCounter(path ...string) StatCounter
GetCounter returns a stat counter object for a path.
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) 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 // SetLogger sets the logging mechanism of the metrics type. SetLogger(log log.Modular) Flat }
Type is an interface for metrics aggregation.
func Combine ¶
Combine returns a Type implementation that feeds metrics into two underlying Type implementations.
func Namespaced ¶
Namespaced embeds an existing metrics aggregator under a new namespace. The prefix of the embedded aggregator is still the ultimate prefix of metrics.
func NewPrometheus ¶
NewPrometheus creates and returns a new Prometheus 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.
type WrappedFlat ¶
type WrappedFlat struct {
// contains filtered or unexported fields
}
WrappedFlat implements the entire Type interface around a Flat type.
func (*WrappedFlat) Close ¶
func (h *WrappedFlat) Close() error
Close stops the WrappedFlat object from aggregating metrics and cleans up resources.
func (*WrappedFlat) Decr ¶
func (h *WrappedFlat) Decr(stat string, value int64) error
Decr decrements a stat by a value.
func (*WrappedFlat) Gauge ¶
func (h *WrappedFlat) Gauge(stat string, value int64) error
Gauge sets a stat as a gauge value.
func (*WrappedFlat) GetCounter ¶
func (h *WrappedFlat) GetCounter(path ...string) StatCounter
GetCounter returns a stat counter object for a path.
func (*WrappedFlat) GetGauge ¶
func (h *WrappedFlat) GetGauge(path ...string) StatGauge
GetGauge returns a stat gauge object for a path.
func (*WrappedFlat) GetTimer ¶
func (h *WrappedFlat) GetTimer(path ...string) StatTimer
GetTimer returns a stat timer object for a path.
func (*WrappedFlat) Incr ¶
func (h *WrappedFlat) Incr(stat string, value int64) error
Incr increments a stat by a value.
func (*WrappedFlat) SetLogger ¶
func (h *WrappedFlat) SetLogger(log log.Modular)
SetLogger does nothing.