Documentation
¶
Index ¶
- Constants
- type DB
- func (d *DB) CleanOldRecords(days int) (int64, error)
- func (d *DB) ClearTargetError(address string) error
- func (d *DB) Close() error
- func (d *DB) CreateTarget(t *Target) error
- func (d *DB) DeleteTarget(id uint) error
- func (d *DB) GetDatabaseStats(dbPath string, retentionDays int) (*DatabaseStats, error)
- func (d *DB) GetFirstUser() (*User, error)
- func (d *DB) GetHistory(target string, start, end time.Time) ([]MonitorRecord, error)
- func (d *DB) GetLatestRecord(target string) (*MonitorRecord, error)
- func (d *DB) GetLatestTrace(target string) (*MonitorRecord, error)
- func (d *DB) GetRecordDetail(id uint) (*MonitorRecord, error)
- func (d *DB) GetTargetByID(id uint) (*Target, error)
- func (d *DB) GetTargets(onlyEnabled bool) ([]Target, error)
- func (d *DB) GetUser(username string) (*User, error)
- func (d *DB) HasAnyUser() bool
- func (d *DB) PruneOldData(retentionDays int) error
- func (d *DB) SaveRecord(r *MonitorRecord) error
- func (d *DB) SaveTarget(t *Target) error
- func (d *DB) SaveUser(u *User) error
- func (d *DB) UpdateTarget(t *Target) error
- func (d *DB) UpdateTargetError(address string, errMsg string) error
- func (d *DB) UpdateUserPassword(userID uint, hashedPassword string) error
- func (d *DB) VacuumDatabase() error
- type DatabaseStats
- type MonitorRecord
- type Target
- type User
Constants ¶
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 (*DB) CleanOldRecords ¶ added in v1.4.0
CleanOldRecords deletes records older than the specified number of days
func (*DB) ClearTargetError ¶ added in v1.2.0
ClearTargetError clears the error fields for a target (on successful probe)
func (*DB) CreateTarget ¶ added in v1.3.2
CreateTarget inserts a new target. Returns error if address already exists.
func (*DB) DeleteTarget ¶
func (*DB) GetDatabaseStats ¶ added in v1.4.0
func (d *DB) GetDatabaseStats(dbPath string, retentionDays int) (*DatabaseStats, error)
GetDatabaseStats returns statistics about the database
func (*DB) GetFirstUser ¶ added in v1.3.2
GetFirstUser returns the first user in the database (single-user system)
func (*DB) GetHistory ¶
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) GetTargetByID ¶ added in v1.3.2
GetTargetByID retrieves a target by its ID
func (*DB) HasAnyUser ¶
func (*DB) PruneOldData ¶
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 ¶
SaveTarget creates or updates a target based on whether ID is set. WARNING: For updates, prefer UpdateTarget to avoid GORM Save() pitfalls.
func (*DB) UpdateTarget ¶ added in v1.3.2
UpdateTarget updates an existing target by ID. Only updates non-zero fields to avoid overwriting with defaults.
func (*DB) UpdateTargetError ¶ added in v1.2.0
UpdateTargetError updates the last_error and last_error_at fields for a target
func (*DB) UpdateUserPassword ¶ added in v1.3.2
UpdateUserPassword updates the password for a specific user ID This avoids GORM's Save() which can INSERT if ID is missing
func (*DB) VacuumDatabase ¶ added in v1.4.0
VacuumDatabase runs VACUUM to reclaim space
type DatabaseStats ¶ added in v1.4.0
type DatabaseStats struct {
SizeBytes int64 `json:"size_bytes"`
SizeHuman string `json:"size_human"`
RecordCount int64 `json:"record_count"`
TargetCount int64 `json:"target_count"`
OldestRecord string `json:"oldest_record,omitempty"`
NewestRecord string `json:"newest_record,omitempty"`
RetentionDays int `json:"retention_days"`
}
DatabaseStats returns database statistics
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"`
// --- Error Tracking (Phase Polish) ---
// LastError stores the most recent probe error message
LastError string `gorm:"column:last_error;type:text" json:"last_error"`
LastErrorAt *time.Time `gorm:"column:last_error_at" json:"last_error_at"`
}
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