Add logging and fix /agents/ route error
All checks were successful
Build and Release / build (push) Successful in 35s

This commit is contained in:
Ducky SSH User
2025-12-20 07:34:02 +00:00
parent 761b91b031
commit 50dcfcdc83
9 changed files with 158 additions and 65 deletions

View File

@@ -2,6 +2,7 @@ package store
import (
"errors"
"log/slog"
"sync"
"time"
@@ -53,6 +54,7 @@ func (s *Store) UpdateAgent(id string, stat *stats.Stats) {
DiskTotal: stat.DiskTotal,
LastSeen: time.Now(),
}
slog.Debug("Agent stats updated", "agentID", id, "hostname", stat.Hostname, "cpu", stat.CPUUsage)
}
// GetAgent retrieves agent stats by ID.
@@ -60,7 +62,13 @@ func (s *Store) GetAgent(id string) *AgentStats {
s.mu.RLock()
defer s.mu.RUnlock()
return s.agents[id]
agent := s.agents[id]
if agent != nil {
slog.Debug("Agent retrieved", "agentID", id, "hostname", agent.Hostname)
} else {
slog.Debug("Agent not found", "agentID", id)
}
return agent
}
// GetAllAgents returns all agents.
@@ -72,6 +80,7 @@ func (s *Store) GetAllAgents() []*AgentStats {
for _, agent := range s.agents {
agents = append(agents, agent)
}
slog.Debug("All agents retrieved", "count", len(agents))
return agents
}
@@ -81,6 +90,7 @@ func (s *Store) DeleteAgent(id string) {
defer s.mu.Unlock()
delete(s.agents, id)
slog.Debug("Agent deleted", "agentID", id)
}
// UpdateHostname updates the hostname for an agent.
@@ -90,9 +100,11 @@ func (s *Store) UpdateHostname(id string, hostname string) error {
agent, exists := s.agents[id]
if !exists {
slog.Debug("Agent not found for hostname update", "agentID", id)
return ErrAgentNotFound
}
agent.Hostname = hostname
slog.Debug("Agent hostname updated", "agentID", id, "hostname", hostname)
return nil
}