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.
This commit is contained in:
Graham McIntire 2026-02-06 11:23:26 -06:00 committed by Graham McIntire
parent bf4fee4846
commit f17ee2183c
No known key found for this signature in database

View file

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