#!/usr/bin/perl -w use strict; use warnings; use Time::HiRes 'time'; use Storable; use Getopt::Long; my ($match, $skip, $match_re, $skip_re, $sort); GetOptions( 'match=s' => \$match, 'skip=s' => \$skip, 'sort=s' => \$sort, ); # time, hps, one, five or fifteen $sort ||= 'five'; # vhosts, urls, ua or referrer my $type = shift() || 'vhosts'; $match_re = qr/$match/i if $match; $skip_re = qr/$skip/i if $skip; my $data = retrieve("logstats.data"); my $now = time(); show($data, " total\n", $now - $data->{time}); print "$type sorted by $sort\n"; my @stale; foreach my $event (sort { $data->{$type}{$b}{$sort} <=> $data->{$type}{$a}{$sort} } keys %{ $data->{$type} }) { next if $skip and $event =~ m/$skip_re/; next if $match and $event !~ m/$match_re/; my $d = $data->{$type}{$event}; my $t = $now - $d->{time}; if ($t > 60) { push @stale, $event; next; } my $text = ' '; if ($now - $d->{time} < 6) { $text = " * "; } show($d, "$text $event\n", $t); } print "\nstale:\n" if @stale; my $i = 0; foreach my $event (@stale) { my $d = $data->{$type}{$event}; my $t = $now - $d->{time}; show($d, " $event\n", $t); last if ++$i > 100; } sub show { my $data = $_[0]; print scalar localtime($data->{time}); my $s = "s"; $s = " " if sprintf("%.0f", $_[2]) eq '1'; printf " hps: %6.0f, average: %.2f, %.2f, %.2f, %2.0f second$s ago, ", $data->{hps}, $data->{one}, $data->{five}, $data->{fifteen}, $_[2]; print $_[1] || "\n"; }