stats

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewServerCollector

func NewServerCollector() *serverCollector

NewServerCollector returns a new collector for collecting server traffic statistics.

Types

type Collector

type Collector interface {
	// CollectTCPSession collects the TCP session's traffic statistics.
	CollectTCPSession(username string, downlinkBytes, uplinkBytes uint64)

	// CollectUDPSessionDownlink collects the UDP session's downlink traffic statistics.
	CollectUDPSessionDownlink(username string, downlinkPackets, downlinkBytes uint64)

	// CollectUDPSessionUplink collects the UDP session's uplink traffic statistics.
	CollectUDPSessionUplink(username string, uplinkPackets, uplinkBytes uint64)

	// Snapshot returns the server's traffic statistics.
	Snapshot() Server

	// SnapshotAndReset returns the server's traffic statistics and resets the statistics.
	SnapshotAndReset() Server
}

Collector collects server traffic statistics.

type Config

type Config struct {
	Enabled bool `json:"enabled"`
}

Config stores configuration for the stats collector.

func (Config) Collector

func (c Config) Collector() Collector

Collector returns a new stats collector from the config.

type NoopCollector

type NoopCollector struct{}

NoopCollector is a no-op collector. Its collect methods do nothing and its snapshot method returns empty statistics.

func (NoopCollector) CollectTCPSession

func (NoopCollector) CollectTCPSession(username string, downlinkBytes, uplinkBytes uint64)

CollectTCPSession implements the Collector CollectTCPSession method.

func (NoopCollector) CollectUDPSessionDownlink(username string, downlinkPackets, downlinkBytes uint64)

CollectUDPSessionDownlink implements the Collector CollectUDPSessionDownlink method.

func (NoopCollector) CollectUDPSessionUplink(username string, uplinkPackets, uplinkBytes uint64)

CollectUDPSessionUplink implements the Collector CollectUDPSessionUplink method.

func (NoopCollector) Snapshot

func (NoopCollector) Snapshot() Server

Snapshot implements the Collector Snapshot method.

func (NoopCollector) SnapshotAndReset

func (NoopCollector) SnapshotAndReset() Server

SnapshotAndReset implements the Collector SnapshotAndReset method.

type Server

type Server struct {
	Traffic
	Users []User `json:"users,omitempty"`
}

Server stores the server's traffic statistics.

type Traffic

type Traffic struct {
	DownlinkPackets uint64 `json:"downlinkPackets"`
	DownlinkBytes   uint64 `json:"downlinkBytes"`
	UplinkPackets   uint64 `json:"uplinkPackets"`
	UplinkBytes     uint64 `json:"uplinkBytes"`
	TCPSessions     uint64 `json:"tcpSessions"`
	UDPSessions     uint64 `json:"udpSessions"`
}

Traffic stores the traffic statistics.

func (*Traffic) Add

func (t *Traffic) Add(u Traffic)

type User

type User struct {
	Name string `json:"username"`
	Traffic
}

User stores the user's traffic statistics.

func (User) Compare added in v1.8.0

func (u User) Compare(other User) int

Compare is useful for sorting users by name.

Jump to

Keyboard shortcuts

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