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
40 lines
724 B
Go
40 lines
724 B
Go
package ring
|
|
|
|
type Buffer[T any] struct {
|
|
buf []T
|
|
head int
|
|
size int
|
|
}
|
|
|
|
func NewBuffer[T any](capacity int) Buffer[T] {
|
|
if capacity < 1 {
|
|
capacity = 1
|
|
}
|
|
return Buffer[T]{buf: make([]T, capacity)}
|
|
}
|
|
|
|
// Push adds v, overwriting the oldest entry when the buffer is full.
|
|
func (r *Buffer[T]) Push(v T) {
|
|
cap := len(r.buf)
|
|
if r.size < cap {
|
|
r.buf[(r.head+r.size)%cap] = v
|
|
r.size++
|
|
} else {
|
|
r.buf[r.head] = v
|
|
r.head = (r.head + 1) % cap
|
|
}
|
|
}
|
|
|
|
// Slice returns all entries in insertion order as a new slice.
|
|
func (r *Buffer[T]) Slice() []T {
|
|
if r.size == 0 {
|
|
return nil
|
|
}
|
|
cap := len(r.buf)
|
|
result := make([]T, r.size)
|
|
for i := 0; i < r.size; i++ {
|
|
result[i] = r.buf[(r.head+i)%cap]
|
|
}
|
|
return result
|
|
}
|