feat: init pc-monitor project
- Client: Go-based Windows hardware monitoring (CPU, GPU, memory, disk, network, power) - Server: Go + Gin + SQLite backend with REST API - Frontend: Vue 3 + Element Plus dashboard - Docker deployment support - Windows service installation script
This commit is contained in:
35
server/service/metrics.go
Normal file
35
server/service/metrics.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"pc-monitor-server/model"
|
||||
"pc-monitor-server/repository"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MetricsService struct {
|
||||
repo *repository.MetricsRepository
|
||||
}
|
||||
|
||||
func NewMetricsService(repo *repository.MetricsRepository) *MetricsService {
|
||||
return &MetricsService{repo: repo}
|
||||
}
|
||||
|
||||
func (s *MetricsService) Save(m *model.Metrics) error {
|
||||
return s.repo.Save(m)
|
||||
}
|
||||
|
||||
func (s *MetricsService) GetLatest(deviceID string) (*model.Metrics, error) {
|
||||
return s.repo.GetLatest(deviceID)
|
||||
}
|
||||
|
||||
func (s *MetricsService) GetHistory(deviceID string, start, end time.Time, limit int) ([]model.Metrics, error) {
|
||||
if limit <= 0 {
|
||||
limit = 1000
|
||||
}
|
||||
return s.repo.GetHistory(deviceID, start, end, limit)
|
||||
}
|
||||
|
||||
func (s *MetricsService) Cleanup(retentionDays int) error {
|
||||
before := time.Now().AddDate(0, 0, -retentionDays)
|
||||
return s.repo.Cleanup(before)
|
||||
}
|
||||
Reference in New Issue
Block a user