From de4f1485b17a2dedc36fce5e84ae1115b3220dbc Mon Sep 17 00:00:00 2001 From: GigabiteStudios Date: Sat, 20 Jun 2026 17:38:45 -0500 Subject: [PATCH] fix(nodes): refresh live stats and node creation --- internal/handlers/handlers.go | 8 +++++++- internal/services/node.go | 6 ++---- web/static/js/app.js | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index 1a55601..e23ca66 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -359,6 +359,10 @@ func (h *Handler) NodeOverview(w http.ResponseWriter, r *http.Request) { return } + if node.SSHUsername != "" && node.SSHPassword != "" && h.nodes.StatsStale(node, time.Second) { + _, _ = h.nodes.RefreshNodeStats(r.Context(), node) + } + runs := h.listRuns(r.Context(), nodeID) h.render(w, r, "node", node.Name, nodePageData{ Node: node, @@ -379,7 +383,7 @@ func (h *Handler) NodeStatsAPI(w http.ResponseWriter, r *http.Request) { return } - if node.SSHUsername != "" && node.SSHPassword != "" && h.nodes.StatsStale(node, 5*time.Second) { + if node.SSHUsername != "" && node.SSHPassword != "" && h.nodes.StatsStale(node, time.Second) { _, _ = h.nodes.RefreshNodeStats(r.Context(), node) } @@ -805,6 +809,8 @@ func shellForPage(page string) string { switch page { case "login", "login_otp", "register": return "auth" + case "console": + return "console" default: return "app" } diff --git a/internal/services/node.go b/internal/services/node.go index af37941..84ab2a6 100644 --- a/internal/services/node.go +++ b/internal/services/node.go @@ -149,7 +149,7 @@ func (s *NodeService) SaveNode(ctx context.Context, node *models.Node) error { organization_id, group_id, tag, name, distro, hostname, ip_address, mac_address, ssh_port, ssh_username, ssh_password, package_manager, architecture, kernel_version, cpu_model, memory_total_mb, disk_total_gb, auto_updates_enabled, notes - ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) `, node.OrganizationID, node.GroupID, node.Tag, node.Name, node.Distro, node.Hostname, node.IPAddress, node.MACAddress, node.SSHPort, node.SSHUsername, encryptedPassword, node.PackageManager, node.Architecture, node.KernelVersion, node.CPUModel, node.MemoryTotalMB, node.DiskTotalGB, node.AutoUpdatesEnabled, node.Notes) if err != nil { @@ -235,9 +235,7 @@ echo "DISK=${disk:-0}" echo "UPTIME=${uptime:-0}" ` - output, err := s.RunSSHCommand(ctx, node, strings.Join([]string{ - `sh -c ` + fmt.Sprintf("%q", statsScript), - }, "")) + output, err := s.RunSSHCommand(ctx, node, strings.TrimSpace(statsScript)) if err != nil { return "", err } diff --git a/web/static/js/app.js b/web/static/js/app.js index 06ac4be..0c5bdf1 100644 --- a/web/static/js/app.js +++ b/web/static/js/app.js @@ -215,7 +215,7 @@ document.addEventListener("DOMContentLoaded", () => { }; updateNodeStats(); - window.setInterval(updateNodeStats, 5000); + window.setInterval(updateNodeStats, 1000); } if (dashboardNodes instanceof HTMLElement) {