From Electron Cloud
Jump to: navigation, search
(Graphing convergence of the system clock)
Line 20: Line 20:
 
</pre>
 
</pre>
 
So just create a cron job which does this once per minute:
 
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` >> remotehost-ntp.log
+
  echo `date +%s | cut -c5-12` " " `ntpdc -s remotehost.local | tail -n1 | cut  -c54-64` >> /path/to/remotehost-ntp.log
 
then to graph the data, create a file with all the gnuplot commands:
 
then to graph the data, create a file with all the gnuplot commands:
 
<pre>
 
<pre>

Revision as of 14:12, 12 January 2009

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 it was not disabled you can use it 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

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. 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 I had gnuplot subtract the initial number from the X values so that the X axis starts at time zero. Remotehost-ntp1.png