Documentation
¶
Index ¶
- type Config
- type MetricAggregate
- type MetricPoint
- type SQLiteStorage
- func (s *SQLiteStorage) Close() error
- func (s *SQLiteStorage) GetActiveAlerts(ctx context.Context) ([]model.AlertEvent, error)
- func (s *SQLiteStorage) GetAlertHistory(ctx context.Context, limit int, offset int) ([]model.AlertEvent, error)
- func (s *SQLiteStorage) GetAvailableMetrics(ctx context.Context) ([]string, error)
- func (s *SQLiteStorage) GetDatabaseSize() (int64, error)
- func (s *SQLiteStorage) GetDiagnosticHistory(ctx context.Context, limit int) ([]model.DiagnosticReport, error)
- func (s *SQLiteStorage) GetLatestDiagnosticReport(ctx context.Context) (*model.DiagnosticReport, error)
- func (s *SQLiteStorage) GetMetricAggregate(ctx context.Context, metric string, start, end time.Time) (*MetricAggregate, error)
- func (s *SQLiteStorage) Ping(ctx context.Context) error
- func (s *SQLiteStorage) PruneOlderThan(ctx context.Context, retention time.Duration) (int64, error)
- func (s *SQLiteStorage) QueryMetrics(ctx context.Context, q TimeRangeQuery) ([]MetricPoint, error)
- func (s *SQLiteStorage) SaveAlertEvent(ctx context.Context, alert model.AlertEvent) error
- func (s *SQLiteStorage) SaveDiagnosticReport(ctx context.Context, report *model.DiagnosticReport) error
- func (s *SQLiteStorage) SaveMetricPoint(ctx context.Context, pt MetricPoint) error
- func (s *SQLiteStorage) SaveMetricPoints(ctx context.Context, pts []MetricPoint) error
- func (s *SQLiteStorage) SaveSnapshot(ctx context.Context, snapshot *model.SystemSnapshot) error
- func (s *SQLiteStorage) UpdateAlertStatus(ctx context.Context, id string, status model.AlertStatus, ...) error
- func (s *SQLiteStorage) Vacuum(ctx context.Context) error
- type Storage
- type TimeRangeQuery
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MetricAggregate ¶
type MetricAggregate struct {
Metric string `json:"metric"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Count int64 `json:"count"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Avg float64 `json:"avg"`
Sum float64 `json:"sum"`
P50 float64 `json:"p50"`
P90 float64 `json:"p90"`
P99 float64 `json:"p99"`
StdDev float64 `json:"std_dev"`
}
MetricAggregate represents aggregated statistics over a time window.
type MetricPoint ¶
type MetricPoint struct {
Timestamp time.Time `json:"timestamp"`
Metric string `json:"metric"`
Value float64 `json:"value"`
Hostname string `json:"hostname,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
}
MetricPoint represents a single scalar time-series metric data point.
type SQLiteStorage ¶
type SQLiteStorage struct {
// contains filtered or unexported fields
}
SQLiteStorage implements Storage interface using pure-Go modernc.org/sqlite.
func NewSQLiteStorage ¶
func NewSQLiteStorage(cfg Config) (*SQLiteStorage, error)
NewSQLiteStorage initializes and migrates the SQLite storage database.
func (*SQLiteStorage) Close ¶
func (s *SQLiteStorage) Close() error
Close closes the underlying SQLite database.
func (*SQLiteStorage) GetActiveAlerts ¶
func (s *SQLiteStorage) GetActiveAlerts(ctx context.Context) ([]model.AlertEvent, error)
GetActiveAlerts returns all currently active alerts.
func (*SQLiteStorage) GetAlertHistory ¶
func (s *SQLiteStorage) GetAlertHistory(ctx context.Context, limit int, offset int) ([]model.AlertEvent, error)
GetAlertHistory returns historical alerts sorted by trigger time descending.
func (*SQLiteStorage) GetAvailableMetrics ¶
func (s *SQLiteStorage) GetAvailableMetrics(ctx context.Context) ([]string, error)
GetAvailableMetrics returns a list of all distinct metric names recorded in storage.
func (*SQLiteStorage) GetDatabaseSize ¶
func (s *SQLiteStorage) GetDatabaseSize() (int64, error)
GetDatabaseSize returns the current database file size in bytes.
func (*SQLiteStorage) GetDiagnosticHistory ¶
func (s *SQLiteStorage) GetDiagnosticHistory(ctx context.Context, limit int) ([]model.DiagnosticReport, error)
GetDiagnosticHistory fetches historical diagnostic runs.
func (*SQLiteStorage) GetLatestDiagnosticReport ¶
func (s *SQLiteStorage) GetLatestDiagnosticReport(ctx context.Context) (*model.DiagnosticReport, error)
GetLatestDiagnosticReport retrieves the most recent diagnostic run.
func (*SQLiteStorage) GetMetricAggregate ¶
func (s *SQLiteStorage) GetMetricAggregate(ctx context.Context, metric string, start, end time.Time) (*MetricAggregate, error)
GetMetricAggregate calculates summary statistics for a metric over a time window.
func (*SQLiteStorage) Ping ¶
func (s *SQLiteStorage) Ping(ctx context.Context) error
Ping verifies database responsiveness.
func (*SQLiteStorage) PruneOlderThan ¶
PruneOlderThan removes metrics, alerts, and diagnostics older than the specified retention duration.
func (*SQLiteStorage) QueryMetrics ¶
func (s *SQLiteStorage) QueryMetrics(ctx context.Context, q TimeRangeQuery) ([]MetricPoint, error)
QueryMetrics queries metrics in a time range with optional step decimation.
func (*SQLiteStorage) SaveAlertEvent ¶
func (s *SQLiteStorage) SaveAlertEvent(ctx context.Context, alert model.AlertEvent) error
SaveAlertEvent stores a new or updated alert event.
func (*SQLiteStorage) SaveDiagnosticReport ¶
func (s *SQLiteStorage) SaveDiagnosticReport(ctx context.Context, report *model.DiagnosticReport) error
SaveDiagnosticReport writes a diagnostic report to the database.
func (*SQLiteStorage) SaveMetricPoint ¶
func (s *SQLiteStorage) SaveMetricPoint(ctx context.Context, pt MetricPoint) error
SaveMetricPoint inserts a single metric point.
func (*SQLiteStorage) SaveMetricPoints ¶
func (s *SQLiteStorage) SaveMetricPoints(ctx context.Context, pts []MetricPoint) error
SaveMetricPoints inserts multiple metric points within a single transaction.
func (*SQLiteStorage) SaveSnapshot ¶
func (s *SQLiteStorage) SaveSnapshot(ctx context.Context, snapshot *model.SystemSnapshot) error
SaveSnapshot unpacks standard metrics from a system snapshot and commits them to the database.
func (*SQLiteStorage) UpdateAlertStatus ¶
func (s *SQLiteStorage) UpdateAlertStatus(ctx context.Context, id string, status model.AlertStatus, resolvedAt *time.Time) error
UpdateAlertStatus updates the status and optional resolved timestamp of an alert.
type Storage ¶
type Storage interface {
// Lifecycle
Close() error
Ping(ctx context.Context) error
// Metrics
SaveSnapshot(ctx context.Context, snapshot *model.SystemSnapshot) error
SaveMetricPoint(ctx context.Context, pt MetricPoint) error
SaveMetricPoints(ctx context.Context, pts []MetricPoint) error
QueryMetrics(ctx context.Context, q TimeRangeQuery) ([]MetricPoint, error)
GetMetricAggregate(ctx context.Context, metric string, start, end time.Time) (*MetricAggregate, error)
GetAvailableMetrics(ctx context.Context) ([]string, error)
// Alerts
SaveAlertEvent(ctx context.Context, alert model.AlertEvent) error
UpdateAlertStatus(ctx context.Context, id string, status model.AlertStatus, resolvedAt *time.Time) error
GetAlertHistory(ctx context.Context, limit int, offset int) ([]model.AlertEvent, error)
GetActiveAlerts(ctx context.Context) ([]model.AlertEvent, error)
// Diagnostics
SaveDiagnosticReport(ctx context.Context, report *model.DiagnosticReport) error
GetLatestDiagnosticReport(ctx context.Context) (*model.DiagnosticReport, error)
GetDiagnosticHistory(ctx context.Context, limit int) ([]model.DiagnosticReport, error)
// Retention & Maintenance
PruneOlderThan(ctx context.Context, retention time.Duration) (int64, error)
GetDatabaseSize() (int64, error)
Vacuum(ctx context.Context) error
}
Storage defines the contract for storing and querying system metrics, alerts, and diagnostics.
type TimeRangeQuery ¶
type TimeRangeQuery struct {
Metric string `json:"metric"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Step time.Duration `json:"step,omitempty"`
Limit int `json:"limit,omitempty"`
}
TimeRangeQuery defines parameters for querying metric time-series.