From Electron Cloud
Jump to: navigation, search
(Versions of ntpd)
(Versions of ntpd)
Line 1: Line 1:
 
==Versions of ntpd==
 
==Versions of ntpd==
* [http://www.ntp.org/downloads.html the reference implementation] (discussed more below)
+
* [http://www.ntp.org/downloads.html the reference implementation] is rather full-featured (discussed more below)
 
* [http://www.openntpd.org/ OpenNTPD] is the one for OpenBSD, also smaller, more secure and suitable for embedded systems
 
* [http://www.openntpd.org/ OpenNTPD] is the one for OpenBSD, also smaller, more secure and suitable for embedded systems
 
* [http://chrony.sunsite.dk/ chrony] claims to be better for systems that are intermittently connected (e.g. dialup) but my experience is that it doesn't behave as well when your system clock has pathological amounts of drift
 
* [http://chrony.sunsite.dk/ chrony] claims to be better for systems that are intermittently connected (e.g. dialup) but my experience is that it doesn't behave as well when your system clock has pathological amounts of drift

Revision as of 16:36, 12 January 2009

Versions of ntpd

  • the reference implementation is rather full-featured (discussed more below)
  • OpenNTPD is the one for OpenBSD, also smaller, more secure and suitable for embedded systems
  • chrony claims to be better for systems that are intermittently connected (e.g. dialup) but my experience is that it doesn't behave as well when your system clock has pathological amounts of drift

Graphing convergence of the system clock

ntpd behaves differently depending on the difference between the system time and the reference clock time(s), various settings etc. You can watch the convergence of the system clock to the references using a cron job to log the data, and gnuplot to graph it.

By default ntpd has a socket interface (or UDP maybe?) which permits querying its status (and maybe even changing some settings) remotely. You can disable that in /etc/ntp.conf:

restrict default nomodify nopeer noquery
restrict 127.0.0.1

(The first line disables some features by default, the second re-enables everything for clients connecting from localhost.) But if "noquery" is omitted, you can use ntpdc to log the offset of a remote host's clock.

[localhost][02:02:12 PM] ntpdc -sn
     remote           local      st poll reach  delay   offset    disp
=======================================================================
*67.192.108.35   192.168.2.114    5   64  377 0.08722 -0.056842 0.14363
 10.90.1.35      192.168.2.114   16 1024    0 0.00000  0.000000 3.99217

~
[localhost][02:02:14 PM] ntpdc -sn remotehost.local
     remote           local      st poll reach  delay   offset    disp
=======================================================================
*67.192.108.35   192.168.2.115    5  128  367 0.08578 -0.072788 0.14655

So just create a cron job which does this once per minute:

echo `date +%s | cut -c5-12` " " `ntpdc -s remotehost.local | tail -n1 | cut  -c54-64` >> /path/to/remotehost-ntp.log

The system clock has its first 4 digits cut off so the numbers are 6 digits, and the log looks like this:

791061   954.35962
791121   954.35130
791181   954.37580
...

Then to graph the data, create a file with all the gnuplot commands:

set style line 1 lt rgb "blue" lw 1 pt 0
set xlabel "time,min"
set ylabel "offset,s"
set title "Convergence of clock via ntpd after startup"
#~ set terminal x11
set terminal png size 1024,400
set output "remotehost-ntp.png"
plot "remotehost-ntp.log" using (($1-791000) / 60):($2) with linespoints ls 1 title 'hostname'

and run it like this

gnuplot -persist ntp-gnuplot

The -persist is for the set terminal x11 case, to make the window stay up until you close it. (If set terminal png ... doesn't work, maybe you need to rebuild gnuplot using gd to get PNG support. X11 previewing is a nice way to just look at the graphs, anyway.) I had gnuplot subtract the initial number from the X values so that the X axis starts at time zero. Remotehost-ntp1.png Well it's not a very interesting graph... when I first installed ntpd on that system I was seeing a very slow convergence over a day or two, but after I started graphing, it started just jumping back to the correct time whenever I perturbed it. Whatever...