# Verifying that NTP is working and device has the correct time

**URL:** <https://forums.balena.io/t/verifying-that-ntp-is-working-and-device-has-the-correct-time/48726>\
**Category:** balenaOS\
**Created:** [December 4, 2019, 10:15pm UTC](https://forums.balena.io/t/verifying-that-ntp-is-working-and-device-has-the-correct-time/48726 "2019-12-04T22:15:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason10](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jason10/32/1464_2.png) [@jason10](https://forums.balena.io/u/jason10)\
**Post date:** [December 4, 2019, 10:15pm UTC](https://forums.balena.io/t/verifying-that-ntp-is-working-and-device-has-the-correct-time/48726/1 "2019-12-04T22:15:02Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![pdcastro](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pdcastro/32/1264_2.png) [@pdcastro](https://forums.balena.io/u/pdcastro)\
**Post date:** [December 4, 2019, 11:17pm UTC](https://forums.balena.io/t/verifying-that-ntp-is-working-and-device-has-the-correct-time/48726/6 "2019-12-04T23:17:59Z")

</div>

If you’re using a relatively recent version of balenaOS, it uses the [chrony](https://chrony.tuxfamily.org/) daemon to synchronise with NTP servers, and the client tool is [chronyc](https://linux.die.net/man/1/chronyc). The `chronyc tracking` command shows some synchronisation stats:

```auto
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:

```auto
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

```

Some more reference links, in case helpful:

- [Lets talk about hardware clocks and time skew, some questions](https://forums.balena.io/t/lets-talk-about-hardware-clocks-and-time-skew-some-questions/29803)
- [https://www.balena.io/docs/reference/OS/time/](https://www.balena.io/docs/reference/OS/time/)
- [https://www.balena.io/docs/reference/OS/network/2.x/#network-requirements](https://www.balena.io/docs/reference/OS/network/2.x/#network-requirements)
- [https://www.balena.io/docs/learn/develop/runtime/#checking-if-device-time-is-ntp-synchronized](https://www.balena.io/docs/learn/develop/runtime/#checking-if-device-time-is-ntp-synchronized)
