#!/usr/bin/perl use warnings; use strict; use Symbol; my @Plot_ASN = qw( 1273 2497 2914 3257 3356 3549 4555 6175 6453 6667 6830 6939 12702 18084 20965 30071 ); ############################################################################## my %Plot_ASN = map { $_ => undef } @Plot_ASN; $Plot_ASN{0} = undef; my $PlotTemplate = join('', ); my %outfh; # fh cache while () { next if /^$/ or /^#/; my ($date, $peeras, @values) = split; die if $peeras !~ /^\d+$/ or not @values; my %asn = map { split(/:/) } @values; my $others = $asn{others}; delete $asn{others}; my @all_asn = keys %asn; foreach my $as (@all_asn) { next if exists $Plot_ASN{$as}; $asn{0} += $asn{$as}; delete $asn{$as}; } my $fh = getfh($peeras); print $fh $date; foreach (@Plot_ASN) { print $fh "\t" . ($asn{$_} ? $asn{$_} : 0); } print $fh "\t$asn{0}\n"; } exit 0; sub getfh { my ($name) = @_; return $outfh{$name} if exists $outfh{$name}; my $fh = gensym; open($fh, ">peer-$name.data") or die "open(peer-$name.data): $!"; print $fh "# date\t\t" . join("\t", map { "AS$_" } @Plot_ASN) . "\tothers\n"; # XXX create_plotfile($name); return $outfh{$name} = $fh; } sub create_plotfile { my ($name) = @_; my $column = 2; my $maxcol = scalar @Plot_ASN + 1; my $otherscol = join('+', map { "\$$_" } $column .. $maxcol + 1); my $plots = qq{"peer-$name.data" using 1:($otherscol) title "others" with boxes, \\\n}; foreach (@Plot_ASN) { my $clist = join('+', map { "\$$_" } $column .. $maxcol); $column++; $plots .= qq{"peer-$name.data" using 1:($clist) title "AS$_" with boxes, \\\n} } $plots =~ s/, \\$//; # ew... my $template = $PlotTemplate; $template =~ s/<-(\S+)->/ eval "\$$1" /gex; open(PLOTFILE, ">peer-$name.gnu") or die "open(peer-$name.gnu): $!"; print PLOTFILE $template; close PLOTFILE or die "close: $!"; } # http://gnuplot.sourceforge.net/demo_4.1/histograms.html __DATA__ #set terminal x11 font "Sans,10" enhanced persist set terminal png xffffff \ font "/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf" \ 10 enhanced size 900,580 set output "peer-<-name->.png" set key out noreverse box linetype -2 linewidth 1.000 samplen 2 spacing 0.7 set key title "peers of AS<-name->" set ylabel "Prefixes" set xlabel "Time" #set yrange [ 0 : * ] set ytics 25 set grid y set grid x set auto x #set xrange ["03/21/2005":"04/28/2005"] set format x "%m/%d" set xdata time set timefmt "%Y-%m-%d" set style fill solid plot <-plots->