7e3e94a08a
Add a comprehensive performance monitoring system that collects CPU, memory, swap, load average, network IO, and GPU stats. Provides both a REST API for the UI and a Prometheus /metrics endpoint. Backend changes: - New internal/perf package with configurable interval-based stats collection - GPU monitoring via LACT (Unix socket) and nvidia-smi fallback on Linux - Ring buffer (internal/ring) for time-series stat storage - Prometheus /metrics endpoint with all system and GPU metrics - Moved LogMonitor to internal/logmon package - New PerformanceConfig for hot-reloadable monitoring settings - REST /api/performance endpoint replacing SSE streaming UI changes: - New Performance page with real-time charts for CPU, memory, GPU, and network - Reusable PerformanceChart component - LLAMA_SWAP_URL environment variable support - Improved capture dialog display Other: - Example Grafana dashboard for Prometheus metrics - monitor-test standalone binary - Config schema and example updates fixes #596
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// PerformanceConfig holds configuration for system performance monitoring
|
|
type PerformanceConfig struct {
|
|
Enable bool `yaml:"enable"`
|
|
Every time.Duration `yaml:"every"`
|
|
MaxAge time.Duration `yaml:"maxAge"`
|
|
GC time.Duration `yaml:"gc"`
|
|
}
|
|
|
|
func (p *PerformanceConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
|
type rawPerformanceConfig PerformanceConfig
|
|
defaults := rawPerformanceConfig{
|
|
Enable: true,
|
|
Every: 15 * time.Second,
|
|
MaxAge: 1 * time.Hour,
|
|
GC: 5 * time.Minute,
|
|
}
|
|
|
|
if err := unmarshal(&defaults); err != nil {
|
|
return err
|
|
}
|
|
|
|
*p = PerformanceConfig(defaults)
|
|
return nil
|
|
}
|
|
|
|
// Validate checks the PerformanceConfig values and returns an error if invalid
|
|
func (p *PerformanceConfig) Validate() error {
|
|
if p.Every < time.Second {
|
|
return fmt.Errorf("every must be at least 1s, got %v", p.Every)
|
|
}
|
|
if p.MaxAge <= 0 {
|
|
return fmt.Errorf("maxAge must be greater than 0, got %v", p.MaxAge)
|
|
}
|
|
if p.GC <= 0 {
|
|
return fmt.Errorf("gc must be greater than 0, got %v", p.GC)
|
|
}
|
|
return nil
|
|
}
|