Time synch monitoring

I'm using a debian variant. My system clock already auto synchronizes. I'd like to have some sort of alert or log entry if the time is ever off by more than a particular amount. My first choice is to have a new file created on the desktop each day that there is a slip greater than the specified time.

Can anyone suggest how to go about this?

You can look at the last line of output from ntpdate -d which gives you the offset from the time servers defined either on the command line on in /etc/ntp.conf

Does that help?

Robin

Filename drift - don't know Debian but it should be in the same directory tree as some other ntp files. It can be named drift or ntp.drift. Some systems have it in /etc/[something] other have it in /var/lib/ntp It gives you an estimate of your computer's clock accuracy - what it is try to correct. The values are ppm. Not seconds.
So, in an 86400 second day 10ppm is 864ms per day correction required. What this means is that ntp has had to add or subtract (if negative) that amount averaged over days of uptime. If you reset file the drift file every day

echo " `date`  `cat /etc/ntp/ntp.drift`" > /someplace/somelogfile
> /etc/ntp/ntp.drift

you get an approximation of the corrections going on for that day.

If you check the file periodically and find major changes (you decide the definition of major) you can report a problem.

Now. Locality of the time server, network, local cpu, and the stratum of your time server all affect accuracy. You should have a single server in your network that connects to a known lower stratum time server. If your time server is in house and NOT going outside, good luck with correct time. If this is for legal purposes, like records you keep and report to external agencies, correct time has to be in order.

If this is scientific or research timing between systems, especially logging boxes, is very important. Correct time as defined by an external arbiter is not usually a big deal.

What do you need? Going for a really tiny discrepancy in the drift file is not usually required.

If you're running ntp for synchronisation, you can use this command:

ntpq -n -c peers

Resulting in this at my host:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
-46.101.140.169  192.53.103.104   2 u  934 1024  377    1.185    5.395   0.463
*31.172.86.173   192.53.103.108   2 u  833 1024  377    0.908    0.278   0.095
+176.221.42.125  109.229.128.40   3 u  439 1024  377    4.442    0.542   1.656
+85.236.36.4     192.53.103.108   2 u  817 1024  377    6.313    0.926   0.267

The line with the asterisk is the server selected for synchronisation. The second last value is supposedly what you like to have: Offset from source.

If you do use some other software to synchronize, there will be other commands to get the offset. E. g. for chrony it's chronyc tracking.

A more general way would be using ntpdate -q on your timeserver to display the offset, without actually setting the time.

stomp's approach is also valid for a lot of situations. In all cases you still need to tell us what you want.

You have three valid answers depending on context.