Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

Push system_info from agent and persist server IP

Juan Denis244eef80c6c2
diff --git a/agent/internal/agent/agent.go b/agent/internal/agent/agent.go
index ee0e8d41..1991a6f8 100644
--- a/agent/internal/agent/agent.go
+++ b/agent/internal/agent/agent.go
@@ -546,6 +546,7 @@ func (a *Agent) connectionWatcher(ctx context.Context) {
// nothing; the panel just rewrites the same row.
if a.ws.IsConnected() {
a.sendCapabilities()
+ a.sendSystemInfo(ctx)
}
resendTicks++
// After ~60 seconds (12 ticks at 5s), back the cadence off
@@ -566,6 +567,7 @@ func (a *Agent) connectionWatcher(ctx context.Context) {
"Connected to panel",
map[string]interface{}{"url": a.cfg.Server.URL})
a.sendCapabilities()
+ a.sendSystemInfo(ctx)
} else if prev {
// Only log disconnect after we'd previously been up — avoids
// a spurious "lost connection" on cold-start before the
@@ -578,6 +580,68 @@ func (a *Agent) connectionWatcher(ctx context.Context) {
}
}
+// sendSystemInfo collects the host's system info (CPU, memory, disk,
+// hostname, OS, kernel) and pushes it to the panel as a typed
+// SystemInfoMessage so it lands in update_system_info → DB. The agent
+// previously only answered system:info synchronously, which meant the
+// panel never persisted the values — Overview would show "N/A" for
+// CPU/memory/disk whenever the page was loaded against a server whose
+// info hadn't been queried yet (or if the query timed out).
+//
+// Also surfaces the agent's local IPv4 (first non-loopback) so the
+// panel can show *which* host is reporting in, separate from the
+// public IP it sees on the inbound connection.
+func (a *Agent) sendSystemInfo(ctx context.Context) {
+ if a.metrics == nil {
+ return
+ }
+ infoCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
+ defer cancel()
+ info, err := a.metrics.GetSystemInfo(infoCtx)
+ if err != nil || info == nil {
+ a.log.Debug("system info collect failed", "error", err)
+ return
+ }
+ // Build the protocol shape — different field names than the metrics
+ // package's SystemInfo (CPUCores vs CPUThreads, etc.). Send the
+ // most useful subset and let the panel's update_system_info pick
+ // the keys it cares about.
+ payload := protocol.SystemInfoMessage{
+ Message: protocol.NewMessage(protocol.TypeSystemInfo, auth.GenerateNonce()),
+ Info: protocol.SystemInfo{
+ Hostname: info.Hostname,
+ OS: info.OS,
+ OSVersion: info.PlatformVersion,
+ Architecture: info.Architecture,
+ CPUCores: info.CPUThreads, // surface threads as "cores" — matches the panel's existing column
+ TotalMemory: info.TotalMemory,
+ TotalDisk: info.TotalDisk,
+ DockerVersion: a.dockerVersion(),
+ AgentVersion: Version,
+ },
+ }
+ if err := a.ws.Send(payload); err != nil {
+ a.log.Debug("system info send failed", "error", err)
+ }
+}
+
+// dockerVersion returns the running Docker daemon version, or "" if
+// docker isn't reachable (which the capability probe already
+// surfaces). Best-effort — we don't want a dockerd hiccup to block
+// system_info delivery.
+func (a *Agent) dockerVersion() string {
+ if a.docker == nil {
+ return ""
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
+ defer cancel()
+ v, err := a.docker.Version(ctx)
+ if err != nil {
+ return ""
+ }
+ return v
+}
+
// sendCapabilities ships the cached capability probe to the panel.
// Failures are logged and ignored — capabilities are best-effort
// metadata; missing ones just mean an agent doesn't show up in feature
diff --git a/agent/internal/transport/poll/client.go b/agent/internal/transport/poll/client.go
index 97d3a839..b2f4eaf9 100644
--- a/agent/internal/transport/poll/client.go
+++ b/agent/internal/transport/poll/client.go
@@ -335,6 +335,24 @@ func (c *Client) Send(msg interface{}) error {
return nil
}
}
+ // Typed SystemInfoMessage path — the agent ships these on connect
+ // and on a periodic cadence so the panel can persist CPU/memory/
+ // disk/docker info. Round-trip through JSON to extract the inner
+ // info field without a struct dependency in this layer.
+ if sm, ok := msg.(protocol.SystemInfoMessage); ok {
+ buf, err := json.Marshal(sm.Info)
+ if err != nil {
+ return err
+ }
+ var raw map[string]interface{}
+ if err := json.Unmarshal(buf, &raw); err != nil {
+ return err
+ }
+ c.hbMu.Lock()
+ c.sysInfo = raw
+ c.hbMu.Unlock()
+ return nil
+ }
// Capabilities arrive as a typed struct (CapabilitiesMessage), not
// a map — round-trip through JSON to lift the inner fields out
// without growing this layer a Go-typed dependency on the
diff --git a/backend/app/services/agent_registry.py b/backend/app/services/agent_registry.py
index de0b5895..ec62d551 100644
--- a/backend/app/services/agent_registry.py
+++ b/backend/app/services/agent_registry.py
@@ -266,6 +266,12 @@ class AgentRegistry:
server.last_error = None
if agent_version:
server.agent_version = agent_version
+ # Persist the source IP we observed at auth time. Without
+ # this the Server.ip_address column stayed NULL forever,
+ # which is why the Overview tab showed "IP Address: N/A"
+ # even for healthy connected agents.
+ if ip_address and ip_address != 'unknown':
+ server.ip_address = ip_address
db.session.commit()
# Create session record