I’m currently maintain several ntp servers that listed in ntppool.org.
Average of all ntp servers listed there, there must be monitoring using mrtg.
After a little searching and asking questions on the mailing list. Here’s my configuration:
———————getntp.pl———————
################################## #getntp.pl #source : http://www.satsignal.eu/ntp/NTPandMRTG.html #budiw 20120728
$ntp_str = `ntpq -c rv $ARGV[0]`; $val = (split(/\\,/,$ntp_str))[20]; $val =~ s/offset=//i; $val = int ($val + 100); if ($val < 0) { $val = 0; } print "0\\n"; print "$val\\n"; print "0\\n"; print "0\\n";
—————–ntppackets.pl—————————
#!/usr/bin/perl use strict;
################################## #ntppackets.pl #source from ntp mailing lists #http://lists.ntp.org/pipermail/pool/2012-July/006049.html
#### Options #### my $uptimeprog = '/usr/bin/uptime'; # Set to program to give system uptime my $hostnameprog = '/bin/hostname'; # Set to program to give system hostname
##### Nothing below here should have to be changed #####
# Clear path and get uptime delete $ENV{PATH}; delete $ENV{BASH_ENV}; my $uptime = `$uptimeprog`; chomp($uptime); $uptime=substr($uptime,12); my $hostname = `$hostnameprog`; chomp($hostname);
my $received = 0; my $sent = 0; my $status = `/usr/bin/ntpdc -c iostats`; if($status =~ m!received packets:\\s*(-?\\d+)!) { $received=$1 + 2147483648; } if($status =~ m!packets sent:\\s*(-?\\d+)!) { $sent=$1 + 2147483648; }
print "$received\\n$sent\n$uptime\\n$hostname\\n";
-----------mrtg.conf--------------------------- # # NTP Packets #
Title[ntppackets]: XXX NTP packets Target[ntppackets]: `/home/budiw/paket/ntp-mrtg/ntppackets.pl` PageTop[ntppackets]: Received and sent NTP packets for yyy MaxBytes[ntppackets]: 60000 Options[ntppackets]: growright, nopercent YLegend[ntppackets]: #/s ShortLegend[ntppackets]: Legend1[ntppackets]: Received packets/s Legend2[ntppackets]: Sent packets/s Legend3[ntppackets]: Maximal 5 minute received packets/s Legend4[ntppackets]: Maximal 5 minute sent packets/s LegendI[ntppackets]: received packets/s LegendO[ntppackets]: sent packets/s WithPeak[ntppackets]: wmy
# # NTP offsets #
Target[xxx_ntp]: `perl /home/budiw/paket/ntp-mrtg/getntp.pl 127.0.0.1` MaxBytes[xxx_ntp]: 100 MaxBytes2[xxx_ntp]: 200 Unscaled[xxx_ntp]: dwmy Timezone[xxx_ntp]: GMT+7 Title[xxx_ntp]: NTP statistics for XXX - offset from NTP Options[xxx_ntp]: integer, gauge, nopercent, growright YLegend[xxx_ntp]: offset+100 ms ShortLegend[xxx_ntp]: ms LegendI[xxx_ntp]: LegendO[xxx_ntp]: offset: Legend1[xxx_ntp]: n/a Legend2[xxx_ntp]: time offset in ms, with 100ms offset added to ensure it's positive! PageTop[xxx_ntp]: NTP -- XXX
—————–
Here’s one example scripts on action:
NTP – Offsets+100ms
NTP – Received and sent NTP packets for alynne.blankon.in