metrics

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Configuration Errors
	ErrInvalidConfig = errors.ErrInvalidConfig
	ErrInvalidDBPath = errors.ErrorCode("metrics_invalid_db_path")

	// Schema Errors
	ErrSchemaInitFailed       = errors.ErrorCode("metrics_schema_init_failed")
	ErrSchemaValidationFailed = errors.ErrorCode("metrics_schema_validation_failed")
	ErrSchemaMigrationFailed  = errors.ErrorCode("metrics_schema_migration_failed")
	ErrTransactionFailed      = errors.ErrorCode("metrics_transaction_failed")

	// Storage Errors
	ErrStorageAccess = errors.ErrorCode("metrics_storage_access_failed")
	ErrStorageInit   = errors.ErrInitFailed
	ErrStorageClose  = errors.ErrShutdownFailed

	// Service Errors
	ErrServiceShutdown = errors.ErrShutdownFailed

	// Collection Errors
	ErrMetricsCollection = errors.ErrorCode("metrics_metrics_collection_failed")
	ErrInvalidMetrics    = errors.ErrorCode("metrics_invalid_metrics")

	// Operation Errors
	ErrOperationTimeout = errors.ErrTimeout
)
View Source
const (
	SchemaVersion = 1 // Increment version for breaking change

)

Variables

This section is empty.

Functions

func GetCreateTablesSQL

func GetCreateTablesSQL() string

SQL getters for consistent schema usage

func GetInsertMetricSQL

func GetInsertMetricSQL() string

GetInsertMetricSQL returns the SQL to insert a metric

func GetSchemaVersion

func GetSchemaVersion(db *sql.DB) (int, error)

GetSchemaVersion returns the current schema version

func InitSchema

func InitSchema(db *sql.DB) error

InitSchema creates a new database schema with the current version

func TableExists

func TableExists(db *sql.DB, tableName string) (bool, error)

TableExists checks if a table exists

func ValidateAndUpdateSchema

func ValidateAndUpdateSchema(db *sql.DB) error

ValidateAndUpdateSchema checks the schema version and recreates it if needed. If a schema exists but the version doesn't match, it creates a backup before recreating the schema.

Types

type Config

type Config struct {
	DBPath          string
	SchemaVersion   int
	BackupOnMigrate bool
	Enabled         bool
}

func DefaultConfig

func DefaultConfig() Config

func (Config) Validate

func (c Config) Validate() error

type FanMetrics

type FanMetrics struct {
	Current int
	Target  int
}

Domain value objects

type MetricsCollector

type MetricsCollector interface {
	Record(ctx context.Context, snapshot *MetricsSnapshot) error
	Close() error
}

MetricsCollector defines the core domain interface

func NewService

func NewService(cfg Config) (MetricsCollector, error)

type MetricsRepository

type MetricsRepository interface {
	Record(snapshot *MetricsSnapshot) error
	Close() error
}

Repository defines the interface for metrics data storage

func NewRepository

func NewRepository(cfg Config) (MetricsRepository, error)

type MetricsSnapshot

type MetricsSnapshot struct {
	Timestamp   time.Time
	FanSpeed    FanMetrics
	Temperature TempMetrics
	PowerLimit  PowerMetrics
	SystemState StateMetrics
}

MetricsSnapshot represents domain entities

type PowerMetrics

type PowerMetrics struct {
	Current int
	Target  int
	Average int
}

type StateMetrics

type StateMetrics struct {
	AutoFanControl  bool
	PerformanceMode bool
}

type TempMetrics

type TempMetrics struct {
	Current int
	Average int
}

Jump to

Keyboard shortcuts

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