metrics

package
v4.14.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReverseLabelledPath

func ReverseLabelledPath(path string) (name string, tagNames, tagValues []string)

ReverseLabelledPath extracts a name, tag names and tag values from a labelled metric name.

Types

type CloudWatchConfig

type CloudWatchConfig struct {
	session.Config `json:",inline" yaml:",inline"`
	Namespace      string `json:"namespace" yaml:"namespace"`
	FlushPeriod    string `json:"flush_period" yaml:"flush_period"`
}

CloudWatchConfig contains config fields for the CloudWatch metrics type.

func NewCloudWatchConfig

func NewCloudWatchConfig() CloudWatchConfig

NewCloudWatchConfig creates an CloudWatchConfig struct with default values.

type Config

type Config struct {
	Type          string           `json:"type" yaml:"type"`
	Mapping       string           `json:"mapping" yaml:"mapping"`
	AWSCloudWatch CloudWatchConfig `json:"aws_cloudwatch" yaml:"aws_cloudwatch"`
	JSONAPI       JSONAPIConfig    `json:"json_api" yaml:"json_api"`
	InfluxDB      InfluxDBConfig   `json:"influxdb" yaml:"influxdb"`
	None          struct{}         `json:"none" yaml:"none"`
	Prometheus    PrometheusConfig `json:"prometheus" yaml:"prometheus"`
	Statsd        StatsdConfig     `json:"statsd" yaml:"statsd"`
	Logger        LoggerConfig     `json:"logger" yaml:"logger"`
	Plugin        any              `json:"plugin,omitempty" yaml:"plugin,omitempty"`
}

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.

func (*Config) UnmarshalYAML

func (conf *Config) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML ensures that when parsing configs that are in a map or slice the default values are still applied.

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)

Decr does nothing.

func (DudStat) Incr

func (d DudStat) Incr(count int64)

Incr does nothing.

func (DudStat) Set

func (d DudStat) Set(value int64)

Set does nothing.

func (DudStat) Timing

func (d DudStat) Timing(delta int64)

Timing does nothing.

type DudType

type DudType struct {
	ID int
}

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

func (DudType) Close

func (d DudType) Close() error

Close does nothing.

func (DudType) GetCounter

func (d DudType) GetCounter(path string) StatCounter

GetCounter returns a DudStat.

func (DudType) GetCounterVec

func (d DudType) GetCounterVec(path string, n ...string) StatCounterVec

GetCounterVec returns a DudStat.

func (DudType) GetGauge

func (d DudType) GetGauge(path string) StatGauge

GetGauge returns a DudStat.

func (DudType) GetGaugeVec

func (d DudType) GetGaugeVec(path string, n ...string) StatGaugeVec

GetGaugeVec returns a DudStat.

func (DudType) GetTimer

func (d DudType) GetTimer(path string) StatTimer

GetTimer returns a DudStat.

func (DudType) GetTimerVec

func (d DudType) GetTimerVec(path string, n ...string) StatTimerVec

GetTimerVec returns a DudStat.

func (DudType) HandlerFunc

func (d DudType) HandlerFunc() http.HandlerFunc

HandlerFunc returns nil.

type InfluxDBConfig

type InfluxDBConfig struct {
	URL string `json:"url" yaml:"url"`
	DB  string `json:"db" yaml:"db"`

	TLS              btls.Config     `json:"tls" yaml:"tls"`
	Interval         string          `json:"interval" yaml:"interval"`
	Password         string          `json:"password" yaml:"password"`
	PingInterval     string          `json:"ping_interval" yaml:"ping_interval"`
	Precision        string          `json:"precision" yaml:"precision"`
	Timeout          string          `json:"timeout" yaml:"timeout"`
	Username         string          `json:"username" yaml:"username"`
	RetentionPolicy  string          `json:"retention_policy" yaml:"retention_policy"`
	WriteConsistency string          `json:"write_consistency" yaml:"write_consistency"`
	Include          InfluxDBInclude `json:"include" yaml:"include"`

	Tags map[string]string `json:"tags" yaml:"tags"`
}

InfluxDBConfig is config for the influx metrics type.

func NewInfluxDBConfig

func NewInfluxDBConfig() InfluxDBConfig

NewInfluxDBConfig creates an InfluxDBConfig struct with default values.

type InfluxDBInclude

type InfluxDBInclude struct {
	Runtime string `json:"runtime" yaml:"runtime"`
	DebugGC string `json:"debug_gc" yaml:"debug_gc"`
}

InfluxDBInclude contains configuration parameters for optional metrics to include.

type JSONAPIConfig

type JSONAPIConfig struct{}

JSONAPIConfig contains configuration parameters for the JSON API metrics aggregator.

func NewJSONAPIConfig

func NewJSONAPIConfig() JSONAPIConfig

NewJSONAPIConfig returns a new JSONAPIConfig with default values.

type Local

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

Local is a metrics aggregator that stores metrics locally.

func NewLocal

func NewLocal() *Local

NewLocal creates and returns a new Local aggregator.

func (*Local) Close

func (l *Local) Close() error

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

func (*Local) FlushCounters

func (l *Local) FlushCounters() map[string]int64

FlushCounters returns a map of the current state of the metrics paths to counters and then resets the counters to 0.

func (*Local) FlushTimings

func (l *Local) FlushTimings() map[string]metrics.Timer

FlushTimings returns a map of the current state of the metrics paths to counters and then resets the counters to 0.

func (*Local) GetCounter

func (l *Local) GetCounter(path string) StatCounter

GetCounter returns a stat counter object for a path.

func (*Local) GetCounterVec

func (l *Local) GetCounterVec(path string, k ...string) StatCounterVec

GetCounterVec returns a stat counter object for a path and records the labels and values.

func (*Local) GetCounters

func (l *Local) GetCounters() map[string]int64

GetCounters returns a map of metric paths to counters.

func (*Local) GetGauge

func (l *Local) GetGauge(path string) StatGauge

GetGauge returns a stat gauge object for a path.

func (*Local) GetGaugeVec

func (l *Local) GetGaugeVec(path string, k ...string) StatGaugeVec

GetGaugeVec returns a stat timer object for a path with the labels discarded.

func (*Local) GetTimer

func (l *Local) GetTimer(path string) StatTimer

GetTimer returns a stat timer object for a path.

func (*Local) GetTimerVec

func (l *Local) GetTimerVec(path string, k ...string) StatTimerVec

GetTimerVec returns a stat timer object for a path with the labels and values.

func (*Local) GetTimings

func (l *Local) GetTimings() map[string]metrics.Timer

GetTimings returns a map of metric paths to timers.

func (*Local) HandlerFunc

func (l *Local) HandlerFunc() http.HandlerFunc

HandlerFunc returns nil.

type LocalStat

type LocalStat struct {
	Value *int64
}

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

func (*LocalStat) Decr

func (l *LocalStat) Decr(count int64)

Decr decrements a metric by an amount.

func (*LocalStat) Incr

func (l *LocalStat) Incr(count int64)

Incr increments a metric by an amount.

func (*LocalStat) Set

func (l *LocalStat) Set(value int64)

Set sets a gauge metric.

type LocalTiming

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

LocalTiming is a representation of a single metric timing.

func (*LocalTiming) Timing

func (l *LocalTiming) Timing(delta int64)

Timing sets a timing metric.

type LoggerConfig

type LoggerConfig struct {
	PushInterval string `json:"push_interval" yaml:"push_interval"`
	FlushMetrics bool   `json:"flush_metrics" yaml:"flush_metrics"`
}

LoggerConfig contains configuration parameters for the Stdout metrics aggregator.

func NewLoggerConfig

func NewLoggerConfig() LoggerConfig

NewLoggerConfig returns a new StdoutConfig with default values.

type Mapping

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

Mapping is a compiled Bloblang mapping used to rewrite metrics.

func NewMapping

func NewMapping(mapping string, logger log.Modular) (*Mapping, error)

NewMapping parses a Bloblang mapping and returns a metrics mapping.

func (*Mapping) WithStaticVars

func (m *Mapping) WithStaticVars(kvs map[string]any) *Mapping

WithStaticVars adds a map of key/value pairs to the static variables of the metrics mapping. These are variables that will be made available to each invocation of the metrics mapping.

type Namespaced

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

Namespaced wraps a child metrics exporter and exposes a Type API that adds namespacing labels and name prefixes to new.

func NewNamespaced

func NewNamespaced(child Type) *Namespaced

NewNamespaced wraps a metrics exporter and adds prefixes and custom labels.

func Noop

func Noop() *Namespaced

Noop returns a namespaced metrics aggregator with a noop child.

func (*Namespaced) Child

func (n *Namespaced) Child() Type

Child returns the underlying metrics type.

func (*Namespaced) Close

func (n *Namespaced) Close() error

Close stops aggregating stats and cleans up resources.

func (*Namespaced) GetCounter

func (n *Namespaced) GetCounter(path string) StatCounter

GetCounter returns an editable counter stat for a given path.

func (*Namespaced) GetCounterVec

func (n *Namespaced) GetCounterVec(path string, labelNames ...string) StatCounterVec

GetCounterVec returns an editable counter stat for a given path with labels, these labels must be consistent with any other metrics registered on the same path.

func (*Namespaced) GetGauge

func (n *Namespaced) GetGauge(path string) StatGauge

GetGauge returns an editable gauge stat for a given path.

func (*Namespaced) GetGaugeVec

func (n *Namespaced) GetGaugeVec(path string, labelNames ...string) StatGaugeVec

GetGaugeVec returns an editable gauge stat for a given path with labels, these labels must be consistent with any other metrics registered on the same path.

func (*Namespaced) GetTimer

func (n *Namespaced) GetTimer(path string) StatTimer

GetTimer returns an editable timer stat for a given path.

func (*Namespaced) GetTimerVec

func (n *Namespaced) GetTimerVec(path string, labelNames ...string) StatTimerVec

GetTimerVec returns an editable timer stat for a given path with labels, these labels must be consistent with any other metrics registered on the same path.

func (*Namespaced) HandlerFunc

func (n *Namespaced) HandlerFunc() http.HandlerFunc

HandlerFunc returns the http handler of the child.

func (*Namespaced) WithLabels

func (n *Namespaced) WithLabels(labels ...string) *Namespaced

WithLabels returns a namespaced metrics exporter with a new set of labels, which are added to any prior labels.

func (*Namespaced) WithMapping

func (n *Namespaced) WithMapping(m *Mapping) *Namespaced

WithMapping returns a namespaced metrics exporter with a new mapping. Mappings are applied _before_ the prefix and static labels are applied. Mappings already added are executed after this new mapping.

func (*Namespaced) WithStats

func (n *Namespaced) WithStats(s Type) *Namespaced

WithStats returns a namespaced metrics exporter with a different stats implementation.

type PrometheusConfig

type PrometheusConfig struct {
	UseHistogramTiming bool                          `json:"use_histogram_timing" yaml:"use_histogram_timing"`
	HistogramBuckets   []float64                     `json:"histogram_buckets" yaml:"histogram_buckets"`
	AddProcessMetrics  bool                          `json:"add_process_metrics" yaml:"add_process_metrics"`
	AddGoMetrics       bool                          `json:"add_go_metrics" yaml:"add_go_metrics"`
	PushURL            string                        `json:"push_url" yaml:"push_url"`
	PushBasicAuth      PrometheusPushBasicAuthConfig `json:"push_basic_auth" yaml:"push_basic_auth"`
	PushInterval       string                        `json:"push_interval" yaml:"push_interval"`
	PushJobName        string                        `json:"push_job_name" yaml:"push_job_name"`
	FileOutputPath     string                        `json:"file_output_path" yaml:"file_output_path"`
}

PrometheusConfig is config for the Prometheus metrics type.

func NewPrometheusConfig

func NewPrometheusConfig() PrometheusConfig

NewPrometheusConfig creates an PrometheusConfig struct with default values.

type PrometheusPushBasicAuthConfig

type PrometheusPushBasicAuthConfig struct {
	Username string `json:"username" yaml:"username"`
	Password string `json:"password" yaml:"password"`
}

PrometheusPushBasicAuthConfig contains parameters for establishing basic authentication against a push service.

func NewPrometheusPushBasicAuthConfig

func NewPrometheusPushBasicAuthConfig() PrometheusPushBasicAuthConfig

NewPrometheusPushBasicAuthConfig creates a new NewPrometheusPushBasicAuthConfig with default values.

type StatCounter

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

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

type StatCounterVec

type StatCounterVec interface {
	// With returns a StatCounter with a set of label values.
	With(labelValues ...string) StatCounter
}

StatCounterVec creates StatCounters with dynamic labels.

func FakeCounterVec

func FakeCounterVec(f func(...string) StatCounter) StatCounterVec

FakeCounterVec returns a counter vec implementation that ignores labels.

type StatGauge

type StatGauge interface {
	// Set sets the value of a gauge metric.
	Set(value int64)

	// Incr increments a gauge by an amount.
	Incr(count int64)

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

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

type StatGaugeVec

type StatGaugeVec interface {
	// With returns a StatGauge with a set of label values.
	With(labelValues ...string) StatGauge
}

StatGaugeVec creates StatGauges with dynamic labels.

func FakeGaugeVec

func FakeGaugeVec(f func(...string) StatGauge) StatGaugeVec

FakeGaugeVec returns a gauge vec implementation that ignores labels.

type StatTimer

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

StatTimer is a representation of a single timer metric stat, timing values should be presented in nanoseconds for consistency. Interactions with this stat are thread safe.

type StatTimerVec

type StatTimerVec interface {
	// With returns a StatTimer with a set of label values.
	With(labelValues ...string) StatTimer
}

StatTimerVec creates StatTimers with dynamic labels.

func FakeTimerVec

func FakeTimerVec(f func(...string) StatTimer) StatTimerVec

FakeTimerVec returns a timer vec implementation that ignores labels.

type StatsdConfig

type StatsdConfig struct {
	Address     string `json:"address" yaml:"address"`
	FlushPeriod string `json:"flush_period" yaml:"flush_period"`
	TagFormat   string `json:"tag_format" yaml:"tag_format"`
}

StatsdConfig is config for the Statsd metrics type.

func NewStatsdConfig

func NewStatsdConfig() StatsdConfig

NewStatsdConfig creates an StatsdConfig struct with default values.

type Type

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

	// GetCounterVec returns an editable counter stat for a given path with labels,
	// these labels must be consistent with any other metrics registered on the
	// same path.
	GetCounterVec(path string, labelNames ...string) StatCounterVec

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

	// GetTimerVec returns an editable timer stat for a given path with labels,
	// these labels must be consistent with any other metrics registered on the
	// same path.
	GetTimerVec(path string, labelNames ...string) StatTimerVec

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

	// GetGaugeVec returns an editable gauge stat for a given path with labels,
	// these labels must be consistent with any other metrics registered on the
	// same path.
	GetGaugeVec(path string, labelNames ...string) StatGaugeVec

	// HandlerFunc returns an optional HTTP request handler that exposes metrics
	// from the implementation. If nil is returned then no endpoint will be
	// registered.
	HandlerFunc() http.HandlerFunc

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

Type is an interface for metrics aggregation.

func Combine

func Combine(t1, t2 Type) Type

Combine returns a Type implementation that feeds metrics into two underlying Type implementations.

Jump to

Keyboard shortcuts

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