storage

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppHistoryPoint

type AppHistoryPoint struct {
	Date       string `json:"date"`
	BytesIn    int64  `json:"bytes_in"`
	BytesOut   int64  `json:"bytes_out"`
	TotalBytes int64  `json:"total_bytes"`
}

AppHistoryPoint represents usage on a single day for an app

type DaySummary

type DaySummary struct {
	DayDate           string `json:"day_date"`
	TotalBytesIn      int64  `json:"total_bytes_in"`
	TotalBytesOut     int64  `json:"total_bytes_out"`
	TotalBytes        int64  `json:"total_bytes"`
	ExternalBytes     int64  `json:"external_bytes"`
	PrivateBytes      int64  `json:"private_bytes"`
	LoopbackBytes     int64  `json:"loopback_bytes"`
	UnknownBytes      int64  `json:"unknown_bytes"`
	ActiveAppCount    int    `json:"active_app_count"` // Deprecated: use recorded_app_count.
	RecordedAppCount  int    `json:"recorded_app_count"`
	UnattributedBytes int64  `json:"unattributed_bytes"`
}

DaySummary aggregates total traffic for a given calendar day

type IngestionRecord

type IngestionRecord struct {
	Identity   *identity.AppIdentity
	ObservedAt time.Time
	Category   int
	BytesIn    uint64
	BytesOut   uint64
	PacketsIn  uint64
	PacketsOut uint64
}

IngestionRecord represents an incoming usage delta mapped to an AppIdentity

type Storage

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

Storage manages SQLite persistence and metrics storage

func NewStorage

func NewStorage(dbPath string) (*Storage, error)

NewStorage opens SQLite database, sets WAL mode, and applies migrations

func (*Storage) CanonicalKeys

func (s *Storage) CanonicalKeys() (map[string]string, error)

CanonicalKeys is also used to sum live rates for command-name aliases.

func (*Storage) Close

func (s *Storage) Close() error

Close closes the database connection

func (*Storage) GetAppHistory

func (s *Storage) GetAppHistory(appKey string, days int) ([]AppHistoryPoint, error)

GetAppHistory returns daily usage for an application over the past N days

func (*Storage) GetAppsForDay

func (s *Storage) GetAppsForDay(dayDate string, sortBy string) ([]TrafficRecord, error)

GetAppsForDay returns ranked applications for a given day

func (*Storage) GetDaySummary

func (s *Storage) GetDaySummary(dayDate string) (*DaySummary, error)

GetDaySummary returns aggregated day totals

func (*Storage) GetExternalAppHistory added in v1.1.3

func (s *Storage) GetExternalAppHistory(appKey string, days int) ([]AppHistoryPoint, error)

GetExternalAppHistory excludes local and unclassified traffic, including historical records.

func (*Storage) GetExternalAppsForDay added in v1.1.3

func (s *Storage) GetExternalAppsForDay(dayDate string, sortBy string) ([]TrafficRecord, error)

GetExternalAppsForDay excludes local and unclassified traffic, including historical records.

func (*Storage) GetExternalDaySummary added in v1.1.3

func (s *Storage) GetExternalDaySummary(dayDate string) (*DaySummary, error)

GetExternalDaySummary excludes local and unclassified traffic, including historical records.

func (*Storage) ListIdentities

func (s *Storage) ListIdentities() ([]*identity.AppIdentity, error)

func (*Storage) PruneOldHistory

func (s *Storage) PruneOldHistory(retentionDays int) (int64, error)

PruneOldHistory removes fine-grained hourly history older than retentionDays

func (*Storage) RecordInterfaceStats

func (s *Storage) RecordInterfaceStats(ifname string, rxBytes, txBytes uint64) error

RecordInterfaceStats records raw interface counters for reconciliation

func (*Storage) RecordUsage

func (s *Storage) RecordUsage(records []IngestionRecord, localLoc *time.Location) error

RecordUsage writes aggregated flow deltas to SQLite inside an atomic transaction

type TrafficRecord

type TrafficRecord struct {
	AppID       int64                 `json:"app_id"`
	Identity    *identity.AppIdentity `json:"identity"`
	Category    int                   `json:"category"`
	CategoryStr string                `json:"category_str"`
	BytesIn     int64                 `json:"bytes_in"`
	BytesOut    int64                 `json:"bytes_out"`
	TotalBytes  int64                 `json:"total_bytes"`
	PacketsIn   int64                 `json:"packets_in"`
	PacketsOut  int64                 `json:"packets_out"`
}

TrafficRecord represents an aggregated usage record for an application

Jump to

Keyboard shortcuts

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