Fix suspend printing

This commit is contained in:
Sebastiaan de Schaetzen 2025-03-30 15:05:19 +02:00
parent a75ed4bbc4
commit b052f8d897

11
main.go
View File

@ -89,7 +89,6 @@ func main() {
// Start HTTP server with context
srv := startHTTPServer()
usageHistory := make([]ResourceUsage, 0)
ticker := time.NewTicker(checkInterval)
defer ticker.Stop()
@ -120,12 +119,14 @@ mainLoop:
if time.Now().After(nextSleepTime) {
log.Printf("System status before suspend:\n")
log.Printf("- CPU: %.1f%%\n", usageHistory[len(usageHistory)-1].CpuUsage)
log.Printf("- CPU: %.1f%%\n", currentStatus.CpuUsage)
if nvmlAvailable {
log.Printf("- GPU: %.1f%%\n", usageHistory[len(usageHistory)-1].GpuUsage)
log.Printf("- GPU: %.1f%%\n", currentStatus.GpuUsage)
}
log.Printf("- SSH connections: %d\n", usageHistory[len(usageHistory)-1].SshConnections)
log.Printf("- Active users: %d\n", usageHistory[len(usageHistory)-1].ActiveUsers)
log.Printf("- SSH connections: %d\n", currentStatus.SshConnections)
log.Printf("- Active users: %d\n", currentStatus.ActiveUsers)
log.Printf("- Disk I/O: %.1f MB/s\n", currentStatus.DiskIO/(1024*1024))
log.Printf("- Network I/O: %.1f MB/s\n", currentStatus.NetworkIO/(1024*1024))
log.Println("System has been idle for the monitoring period. Suspending...")
if err := suspendSystem(); err != nil {
log.Printf("Failed to suspend system: %v", err)