fix(nodes): refresh live stats and node creation

This commit is contained in:
2026-06-20 17:38:45 -05:00
parent 6c50debcf4
commit de4f1485b1
3 changed files with 10 additions and 6 deletions

View File

@@ -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"
}

View File

@@ -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
}