I want to build a program that monitors hundreds of ntpds, looking for time servers that are out of sync. As a proof of concept attempt, I wrote:
| Posted on 2006-01-05 09:22:38-08 by jeffsilverman |
| I think this is what I am looking for |
|
I want to build a program that monitors hundreds of ntpds, looking for time servers that are out of sync. As a proof of concept attempt, I wrote:
#! /usr/bin/perl
#
#
use Net::NTP;
use POSIX qw(strftime);
my %response = get_ntp_response($ARGV[0]);
foreach my $key (keys %response) {
print "The value of $key is $response{$key}\n";
}
$ref_ts = $response{"Reference Timestamp"};
$xmit_ts =$response{"Transmit Timestamp"};
$orig_ts =$response{"Originate Timestamp"};
print "The difference between the reference timestamp $ref_ts seconds\nand the transmitted timestam
+p $xmit_ts seconds\nis ".($xmit_ts-$ref_ts)." seconds\n";
print "The difference between the reference timestamp $ref_ts seconds\nand the originate timestamp
+$orig_ts seconds\nis ".($orig_ts-$ref_ts)." seconds\n";
I turned off my local ntpd, set the clock forward by 12 hours with the date command and then ran it:
The difference between the reference timestamp 1136451103.62599 seconds
and the transmitted timestamp 1136451497.30825 seconds
is 393.682266712189 seconds
The difference between the reference timestamp 1136451103.62599 seconds
and the originate timestamp 1136494726.16602 seconds
is <b>43622.5400295258</b> seconds
Then I restarted the ntpd, which syncs with another time server, and ran it again and got:
The difference between the reference timestamp 1136451103.62599 seconds
and the transmitted timestamp 1136451538.18832 seconds
is 434.562335014343 seconds
The difference between the reference timestamp 1136451103.62599 seconds
and the originate timestamp 1136451538.12695 seconds
is <b>434.500967025757</b> seconds
But the clocks are not 5-1/2 minutes out of sync:
[jeffs@black ~]$ date; ssh angelb date
Thu Jan 5 01:10:47 PST 2006
Thu Jan 5 01:10:50 PST 2006
[jeffs@black ~]$
I am stll struggling to understand what the code is doing - maybe a little more RTFMing is in order |
| Direct Responses: Write a response |