#!/usr/bin/perl #$Id: squid-top-site.pl,v 1.1.1.1 2002/03/11 07:10:43 wyy Exp $ use strict; my %site; while (defined (my $line = )) { my @a = split (/\s+/, $line); if ($a[3] =~ /^TCP/) { my ($host) = ($a[6] =~ m!^(\w+://.*?)/!); $site{$host}->[0] += $a[4]; if ($a[3] =~ /HIT/) { $site{$host}->[1] += $a[4]; } } } my (@l, $sum); foreach my $s (keys (%site)) { push (@l, [$site{$s}->[0], $site{$s}->[1], $s]); $sum += $site{$s}->[0]; } $sum /= 1000; @l = sort {-($a->[0] <=> $b->[0])} @l; my $ptsum = 0; foreach my $e (@l) { my $ph; if ($e->[0] == 0) { $ph = "undef"; } else { $ph = $e->[1] * 1000 / $e->[0]; } my $pt = $e->[0] / $sum; printf "%4d %4d %15d %12d %4d %s\n", $ptsum, $pt, $e->[0], $e->[1], $ph, $e->[2]; $ptsum += $pt; }