statsstore

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package statsstore persists per-rule cumulative traffic counters to a JSON file with atomic writes, so daemon restarts do not lose upload, download, source-IP denial, or UDP protection totals. It only stores cumulative values; live connection counts and rates are not persisted.

Index

Constants

View Source
const DefaultFilename = "stats.json"

DefaultFilename is the state filename used when no explicit path is set.

View Source
const DefaultQuotaFilename = "quota-state.json"

DefaultQuotaFilename is kept separate from cumulative counters because quota enforcement treats corrupt state at load time as fatal rather than resetting. A failed runtime save does not roll back granted traffic: the ledger gates further reserves until a save succeeds, and a crash may under-count usage by up to one durable chunk per rule and period (see engine.QuotaStateStore).

Variables

This section is empty.

Functions

func ResolvePath

func ResolvePath(configPath, configuredPath, stateDirectory string) string

ResolvePath returns the stats file path. Explicit relative paths are resolved beside the config file; otherwise a service state directory takes precedence over the config directory.

func SameFilePath

func SameFilePath(left, right string) (bool, error)

SameFilePath reports whether two paths identify the same destination. It handles existing hard links and symlinks, plus not-yet-created files whose parent directory can be resolved.

Types

type QuotaStore

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

func NewQuotaStore

func NewQuotaStore(path string) *QuotaStore

func (*QuotaStore) LoadQuotaState

func (store *QuotaStore) LoadQuotaState() ([]engine.QuotaPersistentState, error)

func (*QuotaStore) Path

func (store *QuotaStore) Path() string

func (*QuotaStore) SaveQuotaState

func (store *QuotaStore) SaveQuotaState(records []engine.QuotaPersistentState) error

type Store

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

Store reads and writes cumulative traffic counters at path.

func New

func New(path string) *Store

New returns a store backed by path. An empty path makes Save/Load no-ops.

func (*Store) Load

func (s *Store) Load() ([]engine.TrafficSnapshot, error)

Load reads persisted counters. A missing file returns (nil, nil) (first run). A corrupt or unsupported file returns an error so the caller can log it and start from zero rather than silently losing data.

func (*Store) Path

func (s *Store) Path() string

Path returns the configured file path.

func (*Store) Save

func (s *Store) Save(snapshots []engine.TrafficSnapshot) error

Save atomically writes the cumulative counters (temp file + fsync + rename).

Jump to

Keyboard shortcuts

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