action-list 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/perl
  2. # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the
  16. # Free Software Foundation, Inc.
  17. # 59 Temple Place, Suite 330
  18. # Boston, MA 02111-1307 USA
  19. use Time::ParseDate;
  20. while (<STDIN>) {
  21. m/^(\S+) \S+ \S+ \[(.*?)\] "(.*?)" (\d+)/ or die "Cannot parse:\n$_";
  22. $ip = $1;
  23. $ts = $2;
  24. $url = $3;
  25. $code = $4;
  26. $time = parsedate($ts);
  27. $total++;
  28. if ($url =~ /action=([a-z]+)/) {
  29. $action = $1;
  30. } else {
  31. $action = 'browse'; # default action
  32. }
  33. $action .= " [$code]";
  34. $count{$action}++;
  35. $latest{$action} = $ts; # assuming chronological order in the log file
  36. }
  37. @result = sort {$count{$b} <=> $count{$a}} keys %count;
  38. foreach $action (@result) {
  39. printf "%20s %10d %3d%% %s\n", $action, $count{$action}, 100* $count{$action} / $total,
  40. $latest{$action};
  41. }