metrics

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	AttrListener  = attribute.Key("listener")
	AttrUser      = attribute.Key("user")
	AttrMode      = attribute.Key("mode")
	AttrBackend   = attribute.Key("backend")
	AttrErrorType = attribute.Key("error_type")
	AttrLimitType = attribute.Key("limit_type")
	AttrDirection = attribute.Key("direction")
	AttrDatabase  = attribute.Key("database")
	AttrOperation = attribute.Key("operation")
)

Attribute key constants for metric tagging.

Functions

This section is empty.

Types

type Config

type Config struct {
	Endpoint string              `toml:"endpoint"`
	Interval string              `toml:"interval"`
	Enable   map[string][]string `toml:"enable"`
}

Config mirrors the TOML metrics section.

func (Config) IntervalDuration

func (c Config) IntervalDuration() time.Duration

IntervalDuration parses the interval string. Defaults to 30s.

func (Config) IsMetricEnabled

func (c Config) IsMetricEnabled(name string) bool

IsMetricEnabled returns true if the metric name appears in the enable map.

func (Config) TagsForMetric

func (c Config) TagsForMetric(name string) []string

TagsForMetric returns the tag allow-list for a metric name.

type Metrics

type Metrics struct {

	// Connection metrics.
	ConnActive   metric.Int64UpDownCounter
	ConnTotal    metric.Int64Counter
	ConnDuration metric.Float64Histogram
	ConnRejected metric.Int64Counter

	// Auth metrics.
	AuthAttempts metric.Int64Counter
	AuthFailures metric.Int64Counter
	AuthLatency  metric.Float64Histogram

	// Revalidation metrics.
	RevalAttempts metric.Int64Counter
	RevalFailures metric.Int64Counter

	// Byte metrics.
	BytesRead    metric.Int64Counter
	BytesWritten metric.Int64Counter

	// Limit metrics.
	LimitViolations metric.Int64Counter

	// Provision metrics.
	ProvisionTotal   metric.Int64Counter
	ProvisionLatency metric.Float64Histogram
	ProvisionErrors  metric.Int64Counter

	// Redis metrics.
	RedisOpDuration metric.Float64Histogram
	RedisErrors     metric.Int64Counter

	// System metrics.
	SystemListeners metric.Int64UpDownCounter
	// contains filtered or unexported fields
}

Metrics holds all OTel instruments for waypoint.

func New

func New(ctx context.Context, cfg Config) (*Metrics, error)

New creates a new Metrics instance. If cfg.Endpoint is empty, all instruments are noop (zero overhead). Only metrics listed in cfg.Enable are active.

func NewWithProvider

func NewWithProvider(provider metric.MeterProvider, cfg Config) (*Metrics, error)

NewWithProvider creates Metrics using an explicit MeterProvider (for testing).

func Noop

func Noop() *Metrics

Noop returns a Metrics instance with all noop instruments.

func (*Metrics) Attrs

func (m *Metrics) Attrs(metricName string, kvs ...attribute.KeyValue) metric.MeasurementOption

Attrs filters attributes for the given metric, keeping only tags in that metric's allow-list (or all if "*"). Returns a MeasurementOption.

func (*Metrics) Shutdown

func (m *Metrics) Shutdown(ctx context.Context) error

Shutdown flushes and shuts down the meter provider.

Jump to

Keyboard shortcuts

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