metrics

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReportConnError

func ReportConnError(mc MetricsClientInterface, err error)

reportConnError emits a detailed metric about a connection error, with a tag corresponding to the failure type. If err is not a net.Error, does nothing.

Types

type MetricsClientInterface

type MetricsClientInterface interface {
	AddMetricTags(string, map[string]string) error
	Incr(string, float64) error
	IncrWithTags(string, map[string]string, float64) error
	Gauge(string, float64, float64) error
	Histogram(string, float64, float64) error
	HistogramWithTags(string, float64, map[string]string, float64) error
	Timing(string, time.Duration, float64) error
	TimingWithTags(string, time.Duration, map[string]string, float64) error
	SetStarted()
}

type MockMetricsClient

type MockMetricsClient struct {
	MetricsClientInterface
	// contains filtered or unexported fields
}

MockMetricsClient is a MetricsClient that counts metric updates.

func NewMockMetricsClient

func NewMockMetricsClient() *MockMetricsClient

NewMockMetricsClient returns a new MockMetricsClient that wraps a NoOpMetricsClient with counters to track metric updates.

func (*MockMetricsClient) Gauge

func (m *MockMetricsClient) Gauge(metric string, value float64, rate float64) error

func (*MockMetricsClient) GetCount

func (m *MockMetricsClient) GetCount(metric string, tags map[string]string) (uint64, error)

GetCount returns the number of times metric has been updated since the MockMetricsClient was created. To support GetCount being called with or without tags for a given metric, tagged metrics are counted twice: once for the untagged metric ("foo") and once for the metric with its tags sorted("foo [a b c]").

func (*MockMetricsClient) GetValues

func (m *MockMetricsClient) GetValues(metric string, tags map[string]string) ([]float64, error)

GetValues returns the values stored for a metric metric has been updated since the MockMetricsClient was created. To support GetValues being called with or without tags for a given metric, the values for tagged metrics are recorded twice: once for the untagged metric ("foo") and once for the metric with its tags sorted("foo [a b c]").

func (*MockMetricsClient) Histogram

func (m *MockMetricsClient) Histogram(metric string, value float64, rate float64) error

func (*MockMetricsClient) HistogramWithTags

func (m *MockMetricsClient) HistogramWithTags(
	metric string,
	value float64,
	tags map[string]string,
	rate float64) error

func (*MockMetricsClient) Incr

func (m *MockMetricsClient) Incr(metric string, rate float64) error

func (*MockMetricsClient) IncrWithTags

func (m *MockMetricsClient) IncrWithTags(
	metric string,
	tags map[string]string, rate float64) error

func (*MockMetricsClient) Timing

func (m *MockMetricsClient) Timing(metric string, d time.Duration, rate float64) error

func (*MockMetricsClient) TimingWithTags

func (m *MockMetricsClient) TimingWithTags(
	metric string,
	d time.Duration,
	tags map[string]string,
	rate float64) error

type PrometheusMetricsClient

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

PrometheusMetricsClient attempts to replicate the functionality of the StatsdMetricsClient, but exposing the metrics via a http endpoint

func NewPrometheusMetricsClient

func NewPrometheusMetricsClient(endpoint string, port string) (*PrometheusMetricsClient, error)

func (*PrometheusMetricsClient) AddMetricTags

func (mc *PrometheusMetricsClient) AddMetricTags(
	metric string,
	additionalTags map[string]string) error

func (*PrometheusMetricsClient) Gauge

func (mc *PrometheusMetricsClient) Gauge(
	metric string,
	value float64,
	_ float64) error

func (*PrometheusMetricsClient) GetMetricTags

func (mc *PrometheusMetricsClient) GetMetricTags(metric string) map[string]string

func (*PrometheusMetricsClient) Histogram

func (mc *PrometheusMetricsClient) Histogram(
	metric string,
	value float64,
	rate float64) error

func (*PrometheusMetricsClient) HistogramWithTags

func (mc *PrometheusMetricsClient) HistogramWithTags(
	metric string,
	value float64,
	additionalTags map[string]string,
	_ float64) error

func (*PrometheusMetricsClient) Incr

func (mc *PrometheusMetricsClient) Incr(
	metric string,
	rate float64) error

func (*PrometheusMetricsClient) IncrWithTags

func (mc *PrometheusMetricsClient) IncrWithTags(
	metric string,
	additionalTags map[string]string,
	_ float64) error

func (*PrometheusMetricsClient) SetStarted

func (mc *PrometheusMetricsClient) SetStarted()

func (*PrometheusMetricsClient) Timing

func (mc *PrometheusMetricsClient) Timing(
	metric string,
	duration time.Duration,
	rate float64) error

func (*PrometheusMetricsClient) TimingWithTags

func (mc *PrometheusMetricsClient) TimingWithTags(
	metric string,
	d time.Duration,
	additionalTags map[string]string,
	_ float64) error

type StatsdMetricsClient

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

StatsdMetricsClient is a thin wrapper around statsd.ClientInterface. It is used to allow adding arbitrary tags to Smokescreen metrics.

StatsdMetricsClient is not thread safe and should not be used concurrently.

func NewNoOpMetricsClient

func NewNoOpMetricsClient() *StatsdMetricsClient

NewNoOpMetricsClient returns a StatsdMetricsClient with a no-op statsd client. This can be used when there's no statsd service available to smokescreen.

func NewStatsdMetricsClient

func NewStatsdMetricsClient(addr, namespace string) (*StatsdMetricsClient, error)

NewMetricsClient creates a new StatsdMetricsClient with the provided statsd address and namespace.

func (*StatsdMetricsClient) AddMetricTags

func (mc *StatsdMetricsClient) AddMetricTags(
	metric string,
	additionalTags map[string]string) error

AddMetricTags associates the provided tags slice with a given metric. The metric must be present in the metrics slice.

Once a metric has tags added via AddMetricTags, those tags will *always* be attached whenever that metric is emitted. For example, calling `AddMetricTags(foo, [bar])` will cause the `bar` tag to be added to *every* metric `foo` that is emitted for the lifetime of the StatsdMetricsClient.

This function is not thread safe, and adding persistent tags should only be done while initializing the configuration and prior to running smokescreen.

func (*StatsdMetricsClient) Gauge

func (mc *StatsdMetricsClient) Gauge(
	metric string,
	value float64, rate float64) error

func (*StatsdMetricsClient) GetMetricTags

func (mc *StatsdMetricsClient) GetMetricTags(metric string) []string

GetMetricTags returns the slice of metrics associated with a given metric.

func (*StatsdMetricsClient) Histogram

func (mc *StatsdMetricsClient) Histogram(
	metric string,
	value float64,
	rate float64) error

func (*StatsdMetricsClient) HistogramWithTags

func (mc *StatsdMetricsClient) HistogramWithTags(
	metric string,
	value float64,
	additionalTags map[string]string,
	rate float64) error

func (*StatsdMetricsClient) Incr

func (mc *StatsdMetricsClient) Incr(metric string, rate float64) error

func (*StatsdMetricsClient) IncrWithTags

func (mc *StatsdMetricsClient) IncrWithTags(
	metric string,
	additionalTags map[string]string,
	rate float64) error

func (*StatsdMetricsClient) SetStarted

func (mc *StatsdMetricsClient) SetStarted()

func (*StatsdMetricsClient) StatsdClient

func (mc *StatsdMetricsClient) StatsdClient() statsd.ClientInterface

func (*StatsdMetricsClient) Timing

func (mc *StatsdMetricsClient) Timing(metric string, d time.Duration, rate float64) error

func (*StatsdMetricsClient) TimingWithTags

func (mc *StatsdMetricsClient) TimingWithTags(
	metric string,
	d time.Duration,
	additionalTags map[string]string,
	rate float64) error

Jump to

Keyboard shortcuts

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