go-ntp-check is a ntp cli used to automatically check ntp deviation between local host and a ntp server.
Code based on Socketloop golang get current time from ntp example
Code was modified in order to change
- code return
- server
- verbose mode
# go build # as usual for golang
PS C:\dev\src\projects\ntpcheck> go run .\main.go -v -server time.windows.com
Getting Ntp time from time.windows.com
Ntp time : Wed Nov 11 00:37:01 CET 2020
Local time : Wed Nov 11 00:37:01 CET 2020
Delta is 0s
When you need more precision, add scale and delta
$ ./go-ntp-check.exe -server ntp.uvsq.fr -scale ms -delta 500 -v
NTPCheck getting Ntp time from ntp.uvsq.fr
Ntp time : Mon May 3 09:26:27 CET 2021
Local time : Mon May 3 09:26:27 CET 2021
Delta max set to 500ms, current is 427ms
$ ./go-ntp-check.exe -v -server ntp.uvsq.fr -scale ms -delta 200
NTPCheck getting Ntp time from ntp.uvsq.fr
Ntp time : Mon May 3 09:21:17 CET 2021
Local time : Mon May 3 09:21:16 CET 2021
Delta max set to 200ms, current is 424ms
Local clock is ntp-desynchronised from ntp.uvsq.fr : delta is 424ms
return code is not null when ntp is out of scale
# cat /etc/monit.d/ntpcheck
check program ntpcheck with path "/local/sbin/ntpcheck"
every "30-40 * * * 1-5"
if status > 0 then alert
If you don't correct (return code), monit alerts won't change !