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 ¶
- type Collector
- func (c *Collector) Close() error
- func (c *Collector) Counter(key string) stats.Counter
- func (c *Collector) Flush() error
- func (c *Collector) Gauge(key string) stats.Gauge
- func (c *Collector) HLL(key string) stats.HLL
- func (c *Collector) Restore(snap *Snapshot)
- func (c *Collector) Set(key string) stats.Set
- func (c *Collector) Snapshot() *Snapshot
- func (c *Collector) Timer(key string) stats.Timer
- type Option
- type PersistFunc
- type Snapshot
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.
type Option ¶
type Option func(*Collector)
Option configures the in-memory collector.
func WithBloomSet ¶ added in v0.1.2
WithBloomSet configures all Set() calls to return Bloom filter sets instead of exact map-based sets. This dramatically reduces memory for large-scale deduplication (e.g. 1M users → 1.4 MB vs 80 MB).
Trade-off: Count() is approximate, Members() returns nil, Intersect() returns 0. Has() has no false negatives but may have false positives (~falsePositiveRate).
func WithPersistence ¶
func WithPersistence(fn PersistFunc) Option
WithPersistence sets a persistence function called on Flush().
func WithReservoirTimer ¶ added in v0.1.2
WithReservoirTimer sets a fixed capacity for all Timers, using reservoir sampling instead of storing all samples. This bounds memory usage.
Default (0): store all samples (unbounded). Recommended: 4096 (32 KB per timer, P95 error < 1%).
type PersistFunc ¶
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.