From f17ee2183cbb6851245da24eba5c4b9d9323dafc Mon Sep 17 00:00:00 2001 From: mayor Date: Fri, 6 Feb 2026 11:23:26 -0600 Subject: [PATCH] fix: Use server-side timestamps for agent polling metrics Replaces agent-supplied timestamps with server-side DateTime.utc_now() to prevent clock drift issues between agents from causing weird graphs. All metrics now use consistent server time regardless of polling method: - Agent polling (via WebSocket): server time on receipt - Phoenix polling (direct SNMP): server time on poll (already correct) This ensures time-series data aligns correctly when graphing metrics from devices polled by different agents with potentially different system clocks. --- lib/towerops_web/channels/agent_channel.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/towerops_web/channels/agent_channel.ex b/lib/towerops_web/channels/agent_channel.ex index 568829ca..8dd85260 100644 --- a/lib/towerops_web/channels/agent_channel.ex +++ b/lib/towerops_web/channels/agent_channel.ex @@ -914,7 +914,8 @@ defmodule ToweropsWeb.AgentChannel do defp process_polling_result(device, result, _socket) do snmp_device = device.snmp_device oid_values = Map.new(result.oid_values) - timestamp = DateTime.from_unix!(result.timestamp, :second) + # Use server time to avoid clock drift issues between agents + timestamp = DateTime.utc_now() Logger.info( "Processing polling result for #{device.name}: #{map_size(oid_values)} OIDs, #{length(snmp_device.sensors)} sensors, #{length(snmp_device.interfaces)} interfaces"