metrics

package
v1.63.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 License: Apache-2.0 Imports: 5 Imported by: 157

Documentation

Overview

Package metrics provides an internal abstraction for metrics API, and command line flags for configuring the metrics backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init added in v1.36.0

func Init(m any, factory Factory, globalTags map[string]string) error

Init does the same as MustInit, but returns an error instead of panicking.

func MustInit added in v1.36.0

func MustInit(metrics any, factory Factory, globalTags map[string]string)

MustInit initializes the passed in metrics and initializes its fields using the passed in factory.

It uses reflection to initialize a struct containing metrics fields by assigning new Counter/Gauge/Timer values with the metric name retrieved from the `metric` tag and stats tags retrieved from the `tags` tag.

Note: all fields of the struct must be exported, have a `metric` tag, and be of type Counter or Gauge or Timer.

Errors during Init lead to a panic.

Types

type Counter added in v1.36.0

type Counter interface {
	// Inc adds the given value to the counter.
	Inc(int64)
}

Counter tracks the number of times an event has occurred

var NullCounter Counter = nullCounter{}

NullCounter counter that does nothing

type Factory added in v1.36.0

type Factory interface {
	Counter(metric Options) Counter
	Timer(metric TimerOptions) Timer
	Gauge(metric Options) Gauge
	Histogram(metric HistogramOptions) Histogram

	// Namespace returns a nested metrics factory.
	Namespace(scope NSOptions) Factory
}

Factory creates new metrics

var NullFactory Factory = nullFactory{}

NullFactory is a metrics factory that returns NullCounter, NullTimer, and NullGauge.

type Gauge added in v1.36.0

type Gauge interface {
	// Update the gauge to the value passed in.
	Update(int64)
}

Gauge returns instantaneous measurements of something as an int64 value

var NullGauge Gauge = nullGauge{}

NullGauge gauge that does nothing

type Histogram added in v1.36.0

type Histogram interface {
	// Records the value passed in.
	Record(float64)
}

Histogram that keeps track of a distribution of values.

var NullHistogram Histogram = nullHistogram{}

NullHistogram that does nothing

type HistogramOptions added in v1.36.0

type HistogramOptions struct {
	Name    string
	Tags    map[string]string
	Help    string
	Buckets []float64
}

HistogramOptions defines the information associated with a metric

type NSOptions added in v1.36.0

type NSOptions struct {
	Name string
	Tags map[string]string
}

NSOptions defines the name and tags map associated with a factory namespace

type Options added in v1.36.0

type Options struct {
	Name string
	Tags map[string]string
	Help string
}

Options defines the information associated with a metric

type Stopwatch added in v1.36.0

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

A Stopwatch tracks the execution time of a specific event

func StartStopwatch added in v1.36.0

func StartStopwatch(timer Timer) Stopwatch

StartStopwatch begins recording the executing time of an event, returning a Stopwatch that should be used to stop the recording the time for that event. Multiple events can be occurring simultaneously each represented by different active Stopwatches

func (Stopwatch) ElapsedTime added in v1.36.0

func (s Stopwatch) ElapsedTime() time.Duration

ElapsedTime returns the amount of elapsed time (in time.Duration)

func (Stopwatch) Stop added in v1.36.0

func (s Stopwatch) Stop()

Stop stops executing of the stopwatch and records the amount of elapsed time

type Timer added in v1.36.0

type Timer interface {
	// Records the time passed in.
	Record(time.Duration)
}

Timer accumulates observations about how long some operation took, and also maintains a historgam of percentiles.

var NullTimer Timer = nullTimer{}

NullTimer timer that does nothing

type TimerOptions added in v1.36.0

type TimerOptions struct {
	Name    string
	Tags    map[string]string
	Help    string
	Buckets []time.Duration
}

TimerOptions defines the information associated with a metric

Jump to

Keyboard shortcuts

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