feat(agent): auto-renice top CPU process after 2 consecutive high-CPU reports

- Agent tracks consecutive reports above cpu_threshold (default 90%)
- After renice_consecutive reports (default 2 = 60s sustained), runs
  renice -n 19 on the top CPU process
- Reports the action back in the heartbeat payload
- Backend sends Telegram alert when renice is applied
- All params configurable in agent.yml and install.sh flags

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-06-25 11:17:07 -05:00
co-authored by Claude Sonnet 4.6
parent fd72eec281
commit 66088ce691
4 changed files with 83 additions and 17 deletions
+9 -2
View File
@@ -10,14 +10,16 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/sujit-baniya/fiber-boilerplate/app"
"github.com/sujit-baniya/fiber-boilerplate/pkg/models"
"github.com/sujit-baniya/fiber-boilerplate/pkg/services"
)
// AgentHeartbeat recibe métricas del agente instalado en un servidor.
// Ruta pública: POST /agent/heartbeat — autenticada por token en JSON body.
func AgentHeartbeat(c *fiber.Ctx) error {
type HeartbeatRequest struct {
Token string `json:"token"`
Metricas string `json:"metricas"` // JSON string ya serializado por el agente
Token string `json:"token"`
Metricas string `json:"metricas"`
ReniceAction string `json:"renice_action"`
}
var req HeartbeatRequest
@@ -136,6 +138,11 @@ func AgentHeartbeat(c *fiber.Ctx) error {
}
}
// Notificar por Telegram si el agente aplicó un renice
if req.ReniceAction != "" {
go services.NotificarReniceAction(servidor.Nombre, req.ReniceAction)
}
return c.JSON(fiber.Map{"ok": true, "servidor_id": servidor.ID})
}