Max says…

Avatar

thoughts of a web developer

Analysing Oracle Application Server 9i Webcache Logs

Recently I had cause to report on the usage staff at work made of the corporate intranet. This would ordinarily be a simple enough task if the logs were plain standard Apache logs. However, I was dealing with Oracle9iAS, a very different beast indeed. Oracle9iAS is built on top of a customised version of Apache and incorporates a caching proxy server, the so-called Webcache; an implementation of J2EE called OC4J (Oracle Containers for Java) and various other bells and whistles, making it something of a behamoth.

Because we use the Webcache, I would need to analyse the Webcache access logs for a representative picture of what people are requesting. However, the Webcache does not use a single log file; it uses rolling log files for each day named <access_log.YYYYMMDD>. Also, Webcache does not use a standardised logfile format, it uses a format unique (as far as I know) to Oracle.

My task was to extract the relevant data from the various logfiles. I was only interested in “pages” from Oracle Portal. In this case, a page is a specific Oracle Portal entity, rather than a more genereal web page as you might think. I wrote a small Perl script to grab the necessary lines from each logfile and write them to a file that I would later process with Analog.

Code (perl)
  1.  
  2. #!/usr/bin/perl</code>
  3.  
  4. # USE directives
  5. use Time::Local;
  6. use File::Find;
  7. use Cwd;
  8.  
  9. # ———————————————–
  10.  
  11. # Get elements of the current datetime
  12. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
  13. my $cwd = getcwd();
  14. my $extension;
  15. my $regex;
  16. my $line;
  17. my $pause;
  18. my $thisfile;
  19.  
  20. # Convert year to four digit YYYY format rather than ‘year - 1900′
  21. $year = $year + 1900;
  22.  
  23. # If the month is January, i.e. $mon == 0, then we need to process log files
  24. # from the previous year as well as the previous month, i.e. December or
  25. # $mon == 12.
  26. if ($mon == 0)
  27. {
  28.   $mon = 12;
  29.   $year -= 1;
  30. }
  31.  
  32. # Construct logfile extension as YYYYMM where MM is previous MM.
  33. $extension = length($mon) == 1 ? "$year" . "0" . $mon : "$year" . $mon;
  34.  
  35. # File to output results to.
  36. $outfile = "input.log";
  37.  
  38. # Regex to match Portal page URIs.
  39. $regex = ‘^.*\t/portal/page\?_pageid.*$’;
  40.  
  41. # Run File::Find::find() against each file in the current directory.
  42. find(\&get_date, $cwd);
  43.  
  44. ##
  45. # Callback function for File::Find
  46. # This function is called for every file found in $cwd
  47. ##
  48. sub get_date
  49. {
  50.   my $line;
  51.   my @output_list;
  52.   my @input_list;
  53.  
  54.   # only read log files for previous month
  55.   if ($File::Find::name =~ /access_log\.$extension.*$/)
  56.   {
  57.     $thisfile = $File::Find::name;
  58.  
  59.     # test whether the file we are looking at is a compressed
  60.     # file or not
  61.     if ((substr($File::Find::name, -1)) eq "Z")
  62.     {
  63.       # if it is compressed, uncompress it and
  64.       # take name of file without .Z as the file
  65.       # to operate on afterwards
  66.       print "Uncompressing $File::Find::name…";
  67.       system("uncompress $File::Find::name");
  68.       $thisfile = substr($File::Find::name, 0, -2);
  69.     }
  70.     print "$thisfile\n";
  71.     open(IN_FILE, $thisfile) or die ("Cannot Open File: $!\n");
  72.     open(OUT_FILE, ">>$outfile") or die ("Cannot Open File: $!\n");
  73.     while ($line = <in_file>)
  74.     {
  75.       if ($line =~ $regex)
  76.       {
  77.         print $line;
  78.         print OUT_FILE ($line);
  79.       }
  80.     }
  81.     close(IN_FILE);
  82.     close(OUT_FILE);</in_file>
  83.    
  84.     if ((substr($File::Find::name, -1)) eq "Z")
  85.     {
  86.       # If we uncompressed a compressed file then
  87.       # we must now recompress it.
  88.       $zipfile = substr($File::Find::name, 0, -2);
  89.       print "Compressing $zipfile…";
  90.      system("compress $zipfile");
  91.     }
  92.   }
  93. }
  94.  

No Comments, Comment or Ping

Reply to “Analysing Oracle Application Server 9i Webcache Logs”