action-list 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 3 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, see <http://www.gnu.org/licenses/>.
  16. use Time::ParseDate;
  17. while (<STDIN>) {
  18. m/^(\S+) \S+ \S+ \[(.*?)\] "(.*?)" (\d+)/ or die "Cannot parse:\n$_";
  19. $ip = $1;
  20. $ts = $2;
  21. $url = $3;
  22. $code = $4;
  23. $time = parsedate($ts);
  24. $total++;
  25. if ($url =~ /action=([a-z]+)/) {
  26. $action = $1;
  27. } else {
  28. $action = 'browse'; # default action
  29. }
  30. $action .= " [$code]";
  31. $count{$action}++;
  32. $latest{$action} = $ts; # assuming chronological order in the log file
  33. }
  34. @result = sort {$count{$b} <=> $count{$a}} keys %count;
  35. foreach $action (@result) {
  36. printf "%20s %10d %3d%% %s\n", $action, $count{$action}, 100* $count{$action} / $total,
  37. $latest{$action};
  38. }