statsstore

package
v0.2.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 9 Imported by: 0

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.

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 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