storage

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProbeModeICMP  = "MODE_ICMP"
	ProbeModeHTTP  = "MODE_HTTP"
	ProbeModeSSH   = "MODE_SSH"
	ProbeModeIPERF = "MODE_IPERF"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

func NewDB

func NewDB(dbPath string) (*DB, error)

NewDB initializes the SQLite database

func (*DB) Close

func (d *DB) Close() error

Close closes the underlying db connection (optional, GORM manages pool)

func (*DB) DeleteTarget

func (d *DB) DeleteTarget(id uint) error

func (*DB) GetHistory

func (d *DB) GetHistory(target string, start, end time.Time) ([]MonitorRecord, error)

GetHistory fetches records for a specific target within a time range. Optimization: We exclude TraceJson to reduce I/O for general charts.

func (*DB) GetLatestRecord

func (d *DB) GetLatestRecord(target string) (*MonitorRecord, error)

GetLatestRecord fetches the most recent record for a target

func (*DB) GetLatestTrace

func (d *DB) GetLatestTrace(target string) (*MonitorRecord, error)

GetLatestTrace fetches the most recent record that includes traceroute data

func (*DB) GetRecordDetail

func (d *DB) GetRecordDetail(id uint) (*MonitorRecord, error)

GetRecordDetail fetches the full record including TraceJson by ID

func (*DB) GetTargets

func (d *DB) GetTargets(onlyEnabled bool) ([]Target, error)

func (*DB) GetUser

func (d *DB) GetUser(username string) (*User, error)

func (*DB) HasAnyUser

func (d *DB) HasAnyUser() bool

func (*DB) PruneOldData

func (d *DB) PruneOldData(retentionDays int) error

PruneOldData deletes records older than the specified retention days

func (*DB) SaveRecord

func (d *DB) SaveRecord(r *MonitorRecord) error

SaveRecord persists a monitoring record

func (*DB) SaveTarget

func (d *DB) SaveTarget(t *Target) error

func (*DB) SaveUser

func (d *DB) SaveUser(u *User) error

type MonitorRecord

type MonitorRecord struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time `gorm:"index;not null" json:"created_at"` // Time-series index
	Target    string    `gorm:"index;type:varchar(128);not null" json:"target"`

	// Ping Metrics (Always present)
	LatencyMs  float64 `gorm:"not null" json:"latency_ms"`  // Average RTT in milliseconds
	PacketLoss float64 `gorm:"not null" json:"packet_loss"` // Loss Percentage (0.0 - 100.0)

	// Traceroute Data (JSON Blob)
	TraceJson []byte `gorm:"type:text" json:"trace_json,omitempty"`

	// Speed Test Metrics
	SpeedUp   float64 `gorm:"default:0" json:"speed_up"`   // Mbps
	SpeedDown float64 `gorm:"default:0" json:"speed_down"` // Mbps
}

MonitorRecord represents a single monitoring data point (snapshot)

type Target

type Target struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Name      string    `gorm:"type:varchar(64);not null" json:"name"`
	Address   string    `gorm:"type:varchar(128);uniqueIndex;not null" json:"address"` // IP or Domain
	Desc      string    `gorm:"type:text" json:"desc"`
	Enabled   bool      `gorm:"default:true" json:"enabled"`

	// --- Probing Configuration (Phase 13) ---
	// ProbeMode: ICMP, SSH, HTTP, IPERF3
	ProbeType string `gorm:"column:probe_type;type:varchar(20);default:'MODE_ICMP'" json:"probe_type"`

	// ProbeConfig (JSON stored as text for flexibility)
	// Includes URL for HTTP, Port for Iperf, Credentials for SSH
	ProbeConfig string `gorm:"column:probe_config;type:text" json:"probe_config"`
}

Target represents a monitoring destination

type User

type User struct {
	ID        uint      `gorm:"primaryKey" json:"id"`
	CreatedAt time.Time `gorm:"not null" json:"created_at"`
	Username  string    `gorm:"type:varchar(64);uniqueIndex;not null" json:"username"`
	Password  string    `gorm:"type:varchar(128);not null" json:"-"` // Hashed
}

User represents a system administrator

Jump to

Keyboard shortcuts

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