metrics

package
v1.1.38 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize(thelmaConfig config.Config, iapToken string) error

Initialize replaces the global Metrics instance with one that matches Thelma's configuration. It should be called once during Thelma's initialization by the Thelma builder, and nowhere else.

func Push

func Push() error

Push pushes all metrics recorded by the root aggregator to the Thelma metrics gateway. This should ONLY be called once per Thelma run, by the Thelma root command.

func TaskCompletion

func TaskCompletion(opts Options, duration time.Duration, err error)

TaskCompletion is a convenience function that records the completion of as task as both a counter (indicating the task completed) and a gauge (representing how long the task took to complete): <name>_counter <name>_duration_seconds Both metrics will include an "ok" label that will be "true" if err is nil, "false" otherwise

Types

type CounterMetric

type CounterMetric interface {
	// Inc increments the counter
	Inc()
	// Add adds to the counter
	Add(float64)
}

CounterMetric represents a Counter metric

func Counter

func Counter(opts Options) CounterMetric

Counter returns a new Counter metric. Counters should be used for values that accumulate over time (for example, number of times a task is executed)

type GaugeMetric

type GaugeMetric interface {
	// Set sets the gauge to the given value
	Set(float64)
}

GaugeMetric represents a Gauge metric

func Gauge

func Gauge(opts Options) GaugeMetric

Gauge returns a new Gauge metric. Gauges should be used for values that fluctuate over time (for example, duration of a task)

type Metrics

type Metrics interface {
	// Gauge returns a new Gauge metric. Gauges should be used for values that fluctuate over time (for example, duration of a task)
	Gauge(opts Options) GaugeMetric
	// Counter returns a new Counter metric. Counters should be used for values that accumulate over time (for example, number of times a task is executed)
	Counter(opts Options) CounterMetric
	// TaskCompletion is a convenience function that records the completion of as task as both a counter
	// (indicating the task completed) and a gauge (representing how long the task took to complete):
	// <name>_counter
	// <name>_duration_seconds
	// Both metrics will include an "ok" label that will be "true" if err is nil, "false" otherwise
	TaskCompletion(opts Options, duration time.Duration, err error)
	// WithLabels returns a copy of this Metrics instance with an additional set of configured labels
	WithLabels(map[string]string) Metrics
	// contains filtered or unexported methods
}

Metrics is for aggregating metrics

func New

func New(thelmaConfig config.Config, iapToken string) (Metrics, error)

New returns a new Metrics instance

func Noop

func Noop() Metrics

Noop returns a metrics instance that won't actually push metrics anywhere

func WithLabels

func WithLabels(labels map[string]string) Metrics

WithLabels returns a copy of the root Metrics instance with an additional set of configured labels

type Options

type Options struct {
	// Name of the metric -- will be automatically prefixed with "thelma_"
	Name string
	// Help optional help text for the metric
	Help string
	// Labels optional set of labels to apply to the metric
	Labels map[string]string
}

Options options for a metric

Directories

Path Synopsis
Package labels contains utility functions for generating a standard set of labels for terra.State objects Note that you cannot record two metrics with the same name and a different set of labels; if you do, the prometheus client library will panic.
Package labels contains utility functions for generating a standard set of labels for terra.State objects Note that you cannot record two metrics with the same name and a different set of labels; if you do, the prometheus client library will panic.

Jump to

Keyboard shortcuts

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