I’m wondering what we can do to verify that NTP is working and that a device has the correct time.
One option is to run this command though the dashboard and compare to my local clock
while true; do clear; date "+%Y-%m-%d %T.%3N"; sleep 1; done
Another would be to create a simple webserver using python that returns the current system time and compare that in my browser to my local clock.
We are hunting for a 4 to 8 second discrepancy in our systems, so we don’t need a super precise comparison of clocks between systems, but the more precise the better. The more automated the better.
If you’re using a relatively recent version of balenaOS, it uses the chrony daemon to synchronise with NTP servers, and the client tool is chronyc. The chronyc tracking command shows some synchronisation stats:
root@5d3ffbf:~# chronyc tracking
Reference ID : A29FC87B (162.159.200.123)
Stratum : 4
Ref time (UTC) : Wed Dec 04 22:53:05 2019
System time : 0.000443322 seconds slow of NTP time
Last offset : -0.000107522 seconds
RMS offset : 0.000491016 seconds
Frequency : 6.213 ppm fast
Residual freq : -0.001 ppm
Skew : 0.029 ppm
Root delay : 0.027679516 seconds
Root dispersion : 0.002328631 seconds
Update interval : 1029.6 seconds
Leap status : Normal
Another suggestion/approach is to compare the time reported by the balenaCloud API server with the device’s local time:
root@5d3ffbf:~# echo 'remote:' $(curl --silent --head --insecure https://api.balena-cloud.com/ping | grep -i Date: | sed 's/[Dd]ate: //') && echo 'local:' $(date)
remote: Wed, 04 Dec 2019 22:58:42 GMT
local: Wed Dec 4 22:58:42 UTC 2019