metrics

package
v0.0.0-...-750d6ac Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

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

Counter is a concrete impl of CounterT.

func (*Counter) Add

func (c *Counter) Add(labels map[string]string, value float64) error

Add adds the supplied value to the counter associated with the supplied labels.

func (*Counter) CreationTime

func (c *Counter) CreationTime() time.Time

CreationTime returns the creation time of this metric.

func (*Counter) Metric

func (c *Counter) Metric() *prometheus.CounterVec

Metric returns a pointer to the underlying CounterVec.

type CounterT

type CounterT interface {
	Add(labels map[string]string, value float64) error
	Metric() *prometheus.CounterVec
	CreationTime() time.Time
}

CounterT is an interface for "wrapped" (i.e. owned by the Manager) counters.

type Histogram

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

Histogram is a concrete impl of HistogramT.

func (*Histogram) CreationTime

func (h *Histogram) CreationTime() time.Time

CreationTime returns the creation time of this metric.

func (*Histogram) Metric

func (h *Histogram) Metric() prometheus.ObserverVec

Metric returns the underlying ObserverVec interface.

func (*Histogram) Observe

func (h *Histogram) Observe(labels map[string]string, values []float64) error

Observe records the slice of float64 observations in the histogram associated with the supplied labels.

type HistogramT

type HistogramT interface {
	Observe(labels map[string]string, values []float64) error
	Metric() prometheus.ObserverVec
	CreationTime() time.Time
}

HistogramT is an interface for "wrapped" (i.e. owned by the Manager) histograms.

type Manager

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

Manager is an abstraction for ownership and access to counter and histogram metrics, intended to reduce boilerplate over managing Prometheus metrics directly.

func NewManager

func NewManager(commonLabels map[string]string) *Manager

NewManager returns a Manager configured with the supplied "base" labels. All metrics created by the manager will be curried so as to already have those labels partially applied.

func (*Manager) AddCounter

func (m *Manager) AddCounter(name, help string, labelNames []string) error

AddCounter adds a counter metric with the supplied name, help string, and field labels.

func (*Manager) AddHistogram

func (m *Manager) AddHistogram(name, help string, labelNames []string, buckets []float64) error

AddHistogram adds a histogram metric with the supplied name, help string, field labels, and (optionally) buckets. Pass nil for buckets to use the defaults.

func (*Manager) GetCounter

func (m *Manager) GetCounter(name string) (CounterT, error)

GetCounter returns the counter with the specified name (i.e. passed on an earlier call to AddCounter). Note that the returned counter will already have the base labels supplied to the Manager partially applied.

func (*Manager) GetHistogram

func (m *Manager) GetHistogram(name string) (HistogramT, error)

GetHistogram returns the histogram with the specified name (i.e. passed on an earlier call to AddHistogram). Note that the returned histogram will already have the base labels supplied to the Manager partially applied.

func (*Manager) UnregisterAll

func (m *Manager) UnregisterAll() error

UnregisterAll unregisters all previously created metrics from prometheus.

type ManagerT

type ManagerT interface {
	AddCounter(name, help string, labelNames []string) error
	AddHistogram(name, help string, labelNames []string, buckets []float64) error
	GetCounter(name string) (CounterT, error)
	GetHistogram(name string) (HistogramT, error)
}

ManagerT is an interface representing a Manager (useful for mocks).

Directories

Path Synopsis
Package mock_metrics is a generated GoMock package.
Package mock_metrics is a generated GoMock package.

Jump to

Keyboard shortcuts

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