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

cwmetric

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package cwmetric is the shared shape for services that publish in-process CloudWatch metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Async

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

Async is a bounded, non-blocking emitter: points queue to one worker and are dropped when full. With a window it folds points per series into statistic sets and flushes once per window.

func NewAsync

func NewAsync(ctx context.Context, inner Emitter, size int, window time.Duration) *Async

NewAsync starts one worker forwarding to inner until ctx is done; window <= 0 forwards every point as-is.

func (*Async) Dropped

func (a *Async) Dropped() int64

Dropped reports how many points were discarded because the queue was full.

func (*Async) EmitMetric

func (a *Async) EmitMetric(p Point) error

EmitMetric enqueues p without blocking; a full queue drops it.

type Dimension

type Dimension struct {
	Name  string
	Value string
}

Dimension is a metric dimension name/value pair.

type Emitter

type Emitter interface {
	EmitMetric(p Point) error
}

Emitter publishes metric points to CloudWatch.

type EmitterFunc

type EmitterFunc func(p Point) error

EmitterFunc adapts a function to Emitter.

func (EmitterFunc) EmitMetric

func (f EmitterFunc) EmitMetric(p Point) error

EmitMetric implements Emitter.

type Point

type Point struct {
	Region     string
	Namespace  string
	Name       string
	Unit       string
	Dimensions []Dimension
	Value      float64
	// Samples, when positive, marks a statistic set: Samples observations with Sum, Min and Max.
	Samples float64
	Sum     float64
	Min     float64
	Max     float64
}

Point is one metric data point published to the CloudWatch backend of Region.

type Sink

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

Sink is a lock-free holder for an optional Emitter, safe to read on hot paths.

func (*Sink) Emitter

func (s *Sink) Emitter() Emitter

Emitter returns the installed emitter, or nil.

func (*Sink) Enabled

func (s *Sink) Enabled() bool

Enabled reports whether an emitter is installed.

func (*Sink) Put

func (s *Sink) Put(region, namespace, name, unit string, value float64, dims ...Dimension)

Put emits one data point; it is a no-op when no emitter is installed.

func (*Sink) Set

func (s *Sink) Set(e Emitter)

Set installs e; nil disables emission.

Jump to

Keyboard shortcuts

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