[Pool] Traffic graphs (was: Taking down my NTP server in Turkey)

Anssi Johansson timekeeper at miuku.net
Fri Jul 27 22:41:33 UTC 2012

Budiwijaya kirjoitti:
> Hello,
> On Tue, Jul 24, 2012 at 8:43 PM, Anssi Johansson <timekeeper at miuku.net 
> <mailto:timekeeper at miuku.net>> wrote:
>     Hi, it's been 2.5 years since I set up a NTP server in Turkey to
>     reduce the effects of Turk Telekom's routers querying the pool NTP
>     servers. I think this method has worked quite nicely, with the
>     server serving some 1400-1500 packets/sec on average[1] for the last
>     year. I was hoping that at some point Turk Telekom would reconfigure
>     their routers to not query the pool, but alas, that has not happened.
> Anyone know how to make these graphs ? Where do I have to grab that 
> numbers (ntp packets).
>     [1] http://kameli.miuku.net/stats/__ntppackets.html
>     <http://kameli.miuku.net/stats/ntppackets.html>

This was the fourth request for my stats scripts, so apparently there's 
a need for this kind of information. This time I'm sending this 
information to the list, in case there are more people who want to have 
graphs like this.

I'm using MRTG for drawing the graphs. I suppose there are lots of 
guides about installing MRTG on the web, so I'm not describing that step.

In any case, here's a snippet from my mrtg.cfg:

Title[ntppackets]: kameli.miuku.net NTP packets
Target[ntppackets]: `/home/anssi/mrtg/ntppackets.pl`
PageTop[ntppackets]: <h1>Received and sent NTP packets for 
MaxBytes[ntppackets]: 60000
Options[ntppackets]: growright, nopercent
YLegend[ntppackets]: #/s
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

And ntppackets.pl looks like this:

use strict;

#### Options ####
my $uptimeprog = '/usr/bin/uptime';    # Set to program to give system 
my $hostnameprog = '/bin/hostname';    # Set to program to give system 

##### Nothing below here should have to be changed #####

# Clear path and get uptime
delete $ENV{PATH};
delete $ENV{BASH_ENV};
my $uptime = `$uptimeprog`;
my $hostname = `$hostnameprog`;

my $received = 0;
my $sent = 0;
my $status = `/usr/sbin/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";

The "+ 2147483648" part is there to make the number always positive. My 
version of ntpdc wraps around at 2^31 to -2^31, which confuses MRTG. The 
"+ 2147483648" part makes the scale to be 0 from 2^32.

Hope this helps.

More information about the pool mailing list