metric

package
v0.0.0-...-e1e9d1d Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: BSD-3-Clause Imports: 1 Imported by: 1

Documentation

Overview

Package metric defines the standard interface for metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter interface {
	// Name returns the name of the metric.
	Name() string
	// Inc increments the counter by one.
	Inc(...string)
	// Add increments the counter by increment. It must panic if increment is
	// negative.
	Add(increment float64, labels ...string)
}

Counter is a metric that can only ever increase. Labels are provided as alternating keys and values.

type Gauge

type Gauge interface {
	// Name returns the name of the metric.
	Name() string
	// Inc increments the gauge by one.
	Inc(...string)
	// Dec decrements the gauge by one.
	Dec(...string)
	// Add increments the gauge by delta, which may be negative.
	Add(delta float64, labels ...string)
	// Set sets the gauge to value.
	Set(value float64, labels ...string)
}

Gauge is a metric that represents a value that can go up and down. Labels are provided as alternating keys and values.

type Histogram

type Histogram interface {
	// Name returns the name of the metric.
	Name() string
	// Observe records observation of the specified value.
	Observe(value float64, labels ...string)
}

Histogram records observed values. Labels are provided as alternating keys and values.

type MockCounter

type MockCounter struct {
	NameFunc func() string
	IncFunc  func(...string)
	AddFunc  func(float64, ...string)
}

MockCounter is a test mock for the Counter interface.

func (*MockCounter) Add

func (m *MockCounter) Add(inc float64, labels ...string)

func (*MockCounter) Inc

func (m *MockCounter) Inc(labels ...string)

func (*MockCounter) Name

func (m *MockCounter) Name() string

type MockGauge

type MockGauge struct {
	NameFunc func() string
	IncFunc  func(...string)
	DecFunc  func(...string)
	AddFunc  func(float64, ...string)
	SetFunc  func(float64, ...string)
}

MockGauge is a test mock for the Gauge interface.

func (*MockGauge) Add

func (m *MockGauge) Add(delta float64, labels ...string)

func (*MockGauge) Dec

func (m *MockGauge) Dec(labels ...string)

func (*MockGauge) Inc

func (m *MockGauge) Inc(labels ...string)

func (*MockGauge) Name

func (m *MockGauge) Name() string

func (*MockGauge) Set

func (m *MockGauge) Set(v float64, labels ...string)

type MockHistogram

type MockHistogram struct {
	NameFunc    func() string
	ObserveFunc func(float64, ...string)
}

MockHistogram is a test mock for the Histogram interface.

func (*MockHistogram) Name

func (m *MockHistogram) Name() string

func (*MockHistogram) Observe

func (m *MockHistogram) Observe(v float64, labels ...string)

type MockProvider

type MockProvider struct {
	NewCounterFunc   func(string, float64, ...string) (Counter, error)
	NewGaugeFunc     func(string, float64, ...string) (Gauge, error)
	NewHistogramFunc func(string, float64, ...string) (Histogram, error)
}

MockProvider is a test mock for the Provider interface.

func (*MockProvider) NewCounter

func (m *MockProvider) NewCounter(name string, sample float64, labels ...string) (Counter, error)

func (*MockProvider) NewGauge

func (m *MockProvider) NewGauge(name string, sample float64, labels ...string) (Gauge, error)

func (*MockProvider) NewHistogram

func (m *MockProvider) NewHistogram(name string, sample float64, labels ...string) (Histogram, error)

type Provider

type Provider interface {
	// NewCounter creates a new Counter metric. Labels provided here are
	// common labels applied to all values. The sample is a value between
	// 0 and 1, 1 meaning all values are recorded.
	NewCounter(name string, sample float64, labels ...string) (Counter, error)
	// NewGauge creates a new Gauge metric. Labels provided here are
	// common labels applied to all values. The sample is a value between
	// 0 and 1, 1 meaning all values are recorded.
	NewGauge(name string, sample float64, labels ...string) (Gauge, error)
	// NewHistogram creates a new Histogram metric. Labels provided here are
	// common labels applied to all values. The sample is a value between
	// 0 and 1, 1 meaning all values are recorded.
	NewHistogram(name string, sample float64, labels ...string) (Histogram, error)
}

Provider defines the methods that provide metrics.

Jump to

Keyboard shortcuts

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