monitoring NTP

Tom Metro tmetro-blu-5a1Jt6qxUNc at public.gmane.org
Fri Jul 3 17:53:07 EDT 2009


Dan Ritter wrote:
> You need your monitor to parse the output of 
> 
> ntpq -n -c rv $host
> 
> and compare to local time.

Thanks.

So you mean parsing the time string out of:

[...]
reftime=cdf8176a.fdf3a0c5  Fri, Jul  3 2009  1:36:42.991, poll=6,
clock=cdf81781.889e625e  Fri, Jul  3 2009  1:37:05.533, state=4,
offset=-11.510, frequency=-19.803, jitter=8.887, noise=5.759,

My first thought was the use offset, but that appears to be the offset 
between the remote server and its upstream peer.

The HTML documentation lists the variables, but never really defines 
their meaning. I guess they defer to the RFC, which does define them.

Looks like it may be easier to just use Net::NTP in Perl, if it's going 
to require a script anyway, and and that approach reduces dependency on 
the code being monitored (technically ntpq is separate from ntpd).

For example, this will report the offset between the local machine and a 
specified server:

use Net::NTP;
my $SERVER = 'ntp.example.com';
my %response = get_ntp_response($SERVER);
printf "Offset: %.5f s\n", $response{'Transmit Timestamp'} - time;


I'll extend that to compare the delta to a threshold, and log a critical 
error through syslog if it is exceeded. Then set the script up to run 
occasionally from cron.

  -Tom

-- 
Tom Metro
Venture Logic, Newton, MA, USA
"Enterprise solutions through open source."
Professional Profile: http://tmetro.venturelogic.com/





More information about the Discuss mailing list