feat(agent): persist 7-day metrics history per server heartbeat

- New table servidor_metricas_history (cpu%, ram%, swap%, disco%, tcp, load1)
- Each heartbeat inserts a compact row (~60 bytes)
- GET /app/servidor/:id/metricas-history?horas=24 returns the data
- Daily cron at 3AM purges rows older than 7 days
- ~1.2 MB per server per 7 days at 30s interval

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-25 11:03:16 -05:00
co-authored by Claude Sonnet 4.6
parent 4b98161070
commit ae74d0ef90
5 changed files with 127 additions and 0 deletions
+12
View File
@@ -48,6 +48,18 @@ func IniciarCron() {
return
}
// Purga de historial de métricas — cada noche a las 3 AM (retención 7 días)
if _, err := cronScheduler.AddFunc("0 3 * * *", func() {
if err := models.PurgarMetricasHistory(7); err != nil {
log.Printf("[CRON] Error purgando historial métricas: %v", err)
} else {
log.Println("[CRON] Historial de métricas purgado (>7 días)")
}
}); err != nil {
log.Printf("[CRON] Error registrando tarea purga_metricas: %v", err)
return
}
cronScheduler.Start()
log.Println("[CRON] Scheduler iniciado — vencimientos próximos 8AM, ya vencidos 9AM, Bold polling cada 15min, salud servidores cada 5min")
}