#!/usr/bin/perl use strict; use warnings; use Net::DNS; use DBI; my $samplesize = 10000; my %results = (); $results{'dc1'} = 0; $results{'dc2p'} = 0; $results{'dc3'} = 0; $results{'total_hits'} = 0; my %sites = ( '111.222.333.111' => 'dc1' '111.222.333.222' => 'dc2p', '111.222.333.333' => 'dc3', ); my $res = Net::DNS::Resolver->new( nameservers => [qw(127.0.0.1)], recurse => 0, # debug => 1, ); for(my $i=1; $i <= $samplesize; $i++) { my $query = $res->search("as00.estara.com"); my $j = 1; foreach my $rr ($query->answer) { # Skip over anything but A records next unless $rr->type eq "A"; # Record the results # interested in how many returned & which DC print "Sample $i/$samplesize: address:" . $rr->address . ", site:" . $sites{$rr->address} . "\n"; $results{$sites{$rr->address}}++; $results{'total_hits'}++; $results{'pos-'.$j.'-'.$sites{$rr->address}}++; $j++; } # Reset the position counter $j = 1; # cache-ttl is 20s, so wait until so that we get fresh data sleep 1.1; } print "\n\n#### WRR DNS Results\n"; while (my ($site, $hits) = each(%results)) { my $pcent = ($hits/$results{'total_hits'})*100; my $pcent2 = ($hits/$samplesize)*100; print "$site: $hits, $pcent2% (sample size), $pcent% (total RR)\n"; } my $dsn = "DBI:mysql:database=local;host=localhost;"; my $dbh = DBI->connect($dsn, 'root', ''); my $sth = $dbh->prepare("select content, weight from records where name='as00.estara.com'"); $sth->execute; print "\n\nDesired priorities were:\n"; while (my $ref = $sth->fetchrow_hashref()) { # Desired priorities were.. print $sites{$ref->{'content'}} .' '. $ref->{'weight'}."/100, " . (100-$ref->{'weight'}) ."% \n"; }