Help us shape the future of Go! Take the 2026 Go Developer Survey

metrics

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusSuccess = "success"
	StatusFailure = "failure"

	ReasonError    = "error"
	ReasonConflict = "conflict"
)

Variables

This section is empty.

Functions

func Init

func Init(cfg *config.Server) error

Init initializes and registers the global metrics server.

Types

type Counter

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

func NewCounter

func NewCounter(name, description string, opts ...MetricOption) *Counter

NewCounter creates a new Counter Metric (the values will be cumulative). That means that data collected by the new Metric will be summed before export.

func (*Counter) Add

func (f *Counter) Add(value float64)

func (*Counter) Decrement

func (f *Counter) Decrement()

func (*Counter) Increment

func (f *Counter) Increment()

func (*Counter) With

func (f *Counter) With(labelValues ...LabelValue) *Counter

func (*Counter) WithFailure added in v1.1.0

func (f *Counter) WithFailure(reason string, labelValues ...LabelValue) *Counter

func (*Counter) WithStatus added in v1.1.0

func (f *Counter) WithStatus(status string, labelValues ...LabelValue) *Counter

func (*Counter) WithSuccess added in v1.1.0

func (f *Counter) WithSuccess(labelValues ...LabelValue) *Counter

type Gauge

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

func NewGauge

func NewGauge(name, description string, opts ...MetricOption) *Gauge

NewGauge creates a new Gauge Metric. That means that data collected by the new Metric will export only the last recorded value.

func (*Gauge) Record

func (f *Gauge) Record(value float64)

func (*Gauge) With

func (f *Gauge) With(labelValues ...LabelValue) *Gauge

type GaugeValues

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

type Histogram

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

func NewHistogram

func NewHistogram(name, description string, bounds []float64, opts ...MetricOption) *Histogram

NewHistogram creates a new Metric with an aggregation type of Histogram. This means that the data collected by the Metric will be collected and exported as a histogram, with the specified bounds.

func (*Histogram) Record

func (f *Histogram) Record(value float64)

func (*Histogram) With

func (f *Histogram) With(labelValues ...LabelValue) *Histogram

type Label

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

A Label provides a named dimension for a Metric.

func NewLabel

func NewLabel(key string) Label

NewLabel will attempt to create a new Label.

func (Label) Value

func (l Label) Value(value string) LabelValue

Value creates a new LabelValue for the Label.

type LabelValue

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

A LabelValue represents a Label with a specific value. It is used to record values for a Metric.

func (LabelValue) Key

func (l LabelValue) Key() Label

func (LabelValue) Value

func (l LabelValue) Value() string

type Metadata

type Metadata struct {
	Name        string
	Type        MetricType
	Description string
	Bounds      []float64
}

Metadata records a metric's metadata.

type MetricOption

type MetricOption func(*MetricOptions)

MetricOption encode changes to the options passed to a Metric at creation time.

func WithUnit

func WithUnit(unit Unit) MetricOption

WithUnit provides configuration options for a new Metric, providing unit of measure information for a new Metric.

type MetricOptions

type MetricOptions struct {
	Unit        Unit
	Name        string
	Description string
}

type MetricType

type MetricType string

MetricType is the type of a metric.

const (
	CounterType   MetricType = "Counter"
	GaugeType     MetricType = "Gauge"
	HistogramType MetricType = "Histogram"
)

type Unit

type Unit string

Unit encodes the standard name for describing the quantity measured by a Metric (if applicable).

const (
	None         Unit = "1"
	Bytes        Unit = "By"
	Seconds      Unit = "s"
	Milliseconds Unit = "ms"
)

Predefined units for use with the metrics package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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