Skip to content

comparison of local time against remote ntp server for checking synchronisation deltas or de-synchronisation.

Notifications You must be signed in to change notification settings

thc2cat/go-ntp-check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-ntp-check

go-ntp-check is a ntp cli used to automatically check ntp deviation between local host and a ntp server.

Code base

Code based on Socketloop golang get current time from ntp example

Code was modified in order to change

  • code return
  • server
  • verbose mode

Build

# go build # as usual for golang 

Basic output example

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 

Automating ntp checks via Monit with return code as error

# 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 !

About

comparison of local time against remote ntp server for checking synchronisation deltas or de-synchronisation.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published