metric

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package metric provides types and functions for recording and exporting metrics.

Use this package to collect dimensional metric data points with timestamps and values, and export them to a metrics backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetExporter

func SetExporter(ctx context.Context, exp Exporter) context.Context

SetExporter stores an exporter in the context for metric export.

Types

type Dimension

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

Dimension represents a set of string labels for categorizing metrics.

func New

func New(dimension ...string) *Dimension

New creates a new Dimension with the given string values.

func (*Dimension) Record

func (d *Dimension) Record(ctx context.Context, value float64)

Record creates a metric point with this dimension and the given value at the current time, and exports it using the exporter stored in the context.

func (*Dimension) RecordAt

func (d *Dimension) RecordAt(ctx context.Context, givenTime time.Time, value float64)

RecordAt creates a metric point with this dimension, the given time, and value, and exports it using the exporter stored in the context.

func (*Dimension) Values

func (d *Dimension) Values() []string

Values returns a copy of the dimension values.

type Exporter

type Exporter interface {
	// Export sends a metric data point to the metrics backend.
	// Implementations should manage their own context.
	// No error is returned because the metric package does not handle them.
	Export(p *Point)
}

Exporter defines the interface for exporting metric data points to a backend.

type Point

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

Point represents a metric data point with a dimension, time, and value.

func (*Point) Dimension

func (p *Point) Dimension() []string

Dimension returns the dimension associated with this point.

func (*Point) Time

func (p *Point) Time() time.Time

Time returns the timestamp of this point.

func (*Point) Value

func (p *Point) Value() float64

Value returns the metric value of this point.

Jump to

Keyboard shortcuts

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