metrics

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2022 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package metrics wraps prometheus.Metrics making it a bit easier to manage counters and gauges and also providing a mechanism by which all changes are communicated out via channels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DayLabels

func DayLabels() map[string]string

DayLabels returns a label map with the current date on the format '2006-01-02'

Types

type CountChange added in v0.0.2

type CountChange struct {
	Name      string
	Increment float64
	Labels    map[string]string
}

CountChange represents a change to counter. This instance contains the increment, not the resulting value.

type Counter added in v0.0.2

type Counter interface {
	// Inc increments the counter by 1. Use Add to increment it by arbitrary
	// non-negative values.
	Inc()

	// Add adds the given value to the counter. It panics if the value is <
	// 0.
	Add(float64)
}

Counter is a Metric that represents a single numerical value that only ever goes up.

type Gauge added in v0.0.2

type Gauge interface {
	// Set sets the Gauge to an arbitrary value.
	Set(float64)
	// Inc increments the Gauge by 1. Use Add to increment it by arbitrary
	// values.
	Inc()
	// Dec decrements the Gauge by 1. Use Sub to decrement it by arbitrary
	// values.
	Dec()
	// Add adds the given value to the Gauge. (The value can be negative,
	// resulting in a decrease of the Gauge.)
	Add(float64)
	// Sub subtracts the given value from the Gauge. (The value can be
	// negative, resulting in an increase of the Gauge.)
	Sub(float64)
}

Gauge is a Metric that represents a single numerical value that can arbitrarily go up and down.

type GaugeChange added in v0.0.2

type GaugeChange struct {
	Name   string
	Value  float64
	Labels map[string]string
}

GaugeChange represents a change to a gauge. This instance contains the value that the gauge was changed by, not the resulting value.

type Metrics

type Metrics interface {
	// Counter returns a counter for the given name and labels. Is useful in situation where the counter should be
	// increases by some other value that 1.
	Counter(name string, constLabels map[string]string) Counter

	// IncCounter increases the counter with the given name and labels by 1.
	IncCounter(name string, constLabels map[string]string)

	// Gauge returns a gauge with the given name.
	Gauge(name string) Gauge

	// SetGauge sets the given value in the gauge with the given name.
	SetGauge(name string, v int)
}

Metrics provides the concrete abstraction used by clients of this package.

func New

func New(opts ...Option) Metrics

New creates and returns a new instance of Metrics.

type Option added in v0.0.2

type Option func(collector *optionsCollector)

Option for configuring this package.

func WithOutputChannels added in v0.0.2

func WithOutputChannels(countChan chan<- CountChange, gaugeChan chan<- GaugeChange) Option

WithOutputChannels sets channels which will trigger whenever a counter of gauge is altered. This feature is meant for testing purposes.

Jump to

Keyboard shortcuts

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