Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 69 lines (55 sloc) 1.19 KB
#!/usr/bin/perl
# hits
use strict;
use Data::Dumper;
use Term::ExtendedColor qw(fg);
parse_log(\@ARGV);
pop_ips();
pop_files();
my(%ips, %files);
sub parse_log {
my $log = shift;
my @logs;
if(ref($log) eq 'ARRAY') {
push(@logs, @{$log});
}
else {
push(@logs, $log);
}
for my $logfile(@logs) {
open(my $fh, '<', $logfile) or die($!);
while(my $line = <$fh>) {
my $re = '(.+?)';
$line =~ /^$re $re $re \[$re:$re $re\] "$re $re $re" $re $re/;
my $ip = $1;
my $ref = $2;
my $name = $3;
my $date = $4;
my $time = $5;
my $gmt = $6;
my $req = $7;
my $file = $8;
my $ptcl = $9;
my $code = $10;
my $size = $11;
$ips{$ip}++;
$files{$file}++;
}
}
}
sub pop_ips {
my $sum;
for my $ip(sort {$ips{$a} <=> $ips{$b}} keys(%ips)) {
printf("% 5d %s\n", $ips{$ip}, $ip);
$sum += $ips{$ip};
}
printf("%5s IPs\n", fg('red1', fg('bold', $sum)));
}
sub pop_files {
my $sum;
for my $file(sort {$files{$a}<=> $files{$b}} keys(%files)) {
printf("% 5d %s\n", $files{$file}, $file);
$sum += $files{$file};
}
printf("%5s requests\n", fg('orange2', fg('bold', $sum)));
}