metrics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(registry *Registry) http.Handler

Handler exposes metrics as JSON.

func PrometheusHandler

func PrometheusHandler(registry *Registry) http.Handler

PrometheusHandler exposes metrics in Prometheus text format.

Types

type LatencyBucket

type LatencyBucket struct {
	UpperBound time.Duration `json:"le"`
	Count      int64         `json:"count"`
}

LatencyBucket captures histogram counts.

type LatencySnapshot

type LatencySnapshot struct {
	Count   int64           `json:"count"`
	Total   time.Duration   `json:"total"`
	Min     time.Duration   `json:"min"`
	Max     time.Duration   `json:"max"`
	Buckets []LatencyBucket `json:"buckets"`
}

LatencySnapshot captures latency statistics.

type Registry

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

Registry tracks request metrics.

func New

func New() *Registry

New creates a new registry with default buckets.

func NewWithBuckets

func NewWithBuckets(buckets []time.Duration) *Registry

NewWithBuckets creates a new registry with custom buckets.

func (*Registry) End

func (r *Registry) End(start time.Time, status int, err error)

End records a completed request.

func (*Registry) Snapshot

func (r *Registry) Snapshot() Snapshot

Snapshot returns a copy of metrics data.

func (*Registry) Start

func (r *Registry) Start() time.Time

Start marks the start of a request.

type Snapshot

type Snapshot struct {
	Requests int64           `json:"requests"`
	Errors   int64           `json:"errors"`
	InFlight int64           `json:"in_flight"`
	Latency  LatencySnapshot `json:"latency"`
	Statuses map[int]int64   `json:"statuses"`
}

Snapshot captures current metrics values.

Jump to

Keyboard shortcuts

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