stats

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildInterfaceStats

func BuildInterfaceStats(name, link string, rx, tx int64) []*common.Stat

Types

type Entry

type Entry struct {
	Email          string
	CurrentRx      int64
	CurrentTx      int64
	BaseRx         int64
	BaseTx         int64
	LastActiveTime time.Time
	EndpointIP     string
	IsDeleted      bool
}

Entry tracks stats for one user (map key = public key)

type InterfaceCountersTracker

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

InterfaceCountersTracker tracks delta and reset state for interface-level RX/TX counters.

func NewInterfaceCountersTracker

func NewInterfaceCountersTracker() *InterfaceCountersTracker

func (*InterfaceCountersTracker) Delta

func (t *InterfaceCountersTracker) Delta(currentRx, currentTx int64, reset bool) (int64, int64)

Delta calculates counters relative to the current baseline. On first sample, it sets baseline and returns zero. If counters roll back (interface reset/restart), it rebases and returns zero.

type Sample

type Sample struct {
	PublicKey  string
	Email      string
	Rx         int64
	Tx         int64
	EndpointIP string
}

Sample is a single stats measurement for one WireGuard peer key.

type Tracker

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

Tracker manages stats

func New

func New() *Tracker

New creates a new stats tracker

func (*Tracker) AnyActiveSince

func (st *Tracker) AnyActiveSince(keys []string, cutoff time.Time) bool

AnyActiveSince reports whether any key has activity after the provided cutoff.

func (*Tracker) CleanupDeletedEntries

func (st *Tracker) CleanupDeletedEntries()

CleanupDeletedEntries removes deleted peers once their remaining delta is fully accounted.

func (*Tracker) ClearAllStats

func (st *Tracker) ClearAllStats()

ClearAllStats clears all stats

func (*Tracker) EndpointActivity

func (st *Tracker) EndpointActivity(keys []string) map[string]int64

EndpointActivity returns endpoint IP -> last seen unix timestamp for provided keys. If multiple keys share endpoint IP, the newest timestamp wins.

func (*Tracker) GetStats

func (st *Tracker) GetStats(_ context.Context, keys []string, reset bool) *common.StatResponse

GetStats returns stats for specific public keys (direct map lookup)

func (*Tracker) GetStatsEntries

func (st *Tracker) GetStatsEntries(keys []string) map[string]*Entry

GetStatsEntries returns stats entries for specific public keys

func (*Tracker) GetUsersStats

func (st *Tracker) GetUsersStats(_ context.Context, reset bool) *common.StatResponse

GetUsersStats returns stats for all public keys (all users)

func (*Tracker) MarkCounterReset added in v0.5.5

func (st *Tracker) MarkCounterReset(keys []string)

MarkCounterReset records that the kernel re-created these peers, so their counters restarted at zero. Pending traffic is kept and the next sample counts in full, even when it is already above the old counter. Only mark peers that really were re-created, and never apply a sample read before the reset after this call: either would report the old counter a second time.

func (*Tracker) RemoveStats

func (st *Tracker) RemoveStats(publicKey string)

RemoveStats marks a peer as deleted but keeps counters until a reset reports them.

func (*Tracker) UpdateStatsBatch

func (st *Tracker) UpdateStatsBatch(samples []Sample)

UpdateStatsBatch applies many peer stats updates under a single lock.

Jump to

Keyboard shortcuts

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