memory

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package memory provides an in-memory implementation of stats.Collector. All primitives are goroutine-safe and live in process memory. Use WithPersistence to periodically snapshot to a file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

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

Collector implements stats.Collector with in-memory primitives.

func New

func New(opts ...Option) *Collector

New creates a new in-memory collector.

func (*Collector) Close

func (c *Collector) Close() error

func (*Collector) Counter

func (c *Collector) Counter(key string) stats.Counter

func (*Collector) Flush

func (c *Collector) Flush() error

func (*Collector) Gauge

func (c *Collector) Gauge(key string) stats.Gauge

func (*Collector) HLL

func (c *Collector) HLL(key string) stats.HLL

func (*Collector) Restore

func (c *Collector) Restore(snap *Snapshot)

Restore loads state from a snapshot (replaces existing data).

func (*Collector) Set

func (c *Collector) Set(key string) stats.Set

func (*Collector) Snapshot

func (c *Collector) Snapshot() *Snapshot

Snapshot takes a consistent snapshot of all primitives.

func (*Collector) Timer

func (c *Collector) Timer(key string) stats.Timer

type Option

type Option func(*Collector)

Option configures the in-memory collector.

func WithPersistence

func WithPersistence(fn PersistFunc) Option

WithPersistence sets a persistence function called on Flush().

type PersistFunc

type PersistFunc func(data *Snapshot) error

PersistFunc is called during Flush to serialize state.

type Snapshot

type Snapshot struct {
	Counters map[string]int64    `json:"counters"`
	Gauges   map[string]int64    `json:"gauges"`
	Sets     map[string][]string `json:"sets"`
	HLLs     map[string][]byte   `json:"hlls"`
	Timers   map[string][]int64  `json:"timers"`
}

Snapshot is a serializable representation of the in-memory collector's state. It can be used with gob/json for file persistence.

Jump to

Keyboard shortcuts

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