$ squid-parser.pl 2009-07-12 < squid-access.log | mail blabla@company.com
Собственно, скрипт, наваянный на скорую руку:
#!/usr/bin/perl -w
# aggregates squid logs
use strict;
use POSIX qw(strftime);
my $pattern = $ARGV[0];
my $line;
my @fields;
my $date;
my $ip;
my $bytes;
my $url;
my %ipstats;
my %urlstats;
my %ipurlstats;
while ($line=<STDIN>)
{
@fields = split ' ', $line;
$date=POSIX::strftime("%Y-%m-%d %H:%M:%S", localtime($fields[0]));
$ip=$fields[2];
$bytes=$fields[4];
$url=$fields[6];
$url=~s/.*:\/\/([^\/]*)\/.*/$1/;
if ($date =~ m/$pattern/)
{
$ipstats{$ip}+=$bytes;
$ipurlstats{$ip}{$url}+=$bytes;
}
}
my $urls;
my $mbytes;
while (($ip, $urls) = each (%ipurlstats))
{
print "-------------------------------------------------\n";
print "$ip:\n";
print "----------------------------------------------- \n";
foreach $url (sort {$urls->{$b} <=> $urls->{$a}} (keys %$urls))
{
print "$url: $urls->{$url} bytes \n";
}
$bytes = $ipstats{$ip};
$mbytes = sprintf "%8.3f", $bytes/1024/1024;
print "----------------------------------------------\n";
print "Total: $bytes b ($mbytes MB)\n";
print "----------------------------------------------\n\n";
}
Комментариев нет:
Отправить комментарий