Sha256: f6d54bfd48162d09a1c21d144ec7eac56482a4d774f5cd2af610d6538e1e461f

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

module LogfileInterval
  data_dir = File.join(File.dirname(__FILE__), '..', 'support/logfiles')

  module LineParser

    class AccessLog < Base
      # Example line:
      # 74.75.19.145 - - [31/Mar/2013:06:54:12 -0700] "GET /ppa/google_chrome HTTP/1.1" 200 7855 "https://www.google.com/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.22 (KHTML, like Gecko) Ubuntu Chromium/25.0.1364.160 Chrome/25.0.1364.160 Safari/537.22"

      set_regex /^([\d\.]+)\s+\S+\s+\S+\s+\[(\d\d.*\d\d)\]\s+"(?:GET|POST|PUT|HEAD|DELETE)\s+(\S+)\s+HTTP\S+"\s+(\d+)\s+(\d+)\s+"([^"]*)"\s+"([^"]+)"$/

      add_column :name => 'ip',           :pos => 1, :aggregator => :count,                              :group_by => 'id'
      add_column :name => 'timestamp',    :pos => 2, :aggregator => :timestamp
      add_column :name => 'code',         :pos => 4, :aggregator => :count,                              :group_by => 'id'
      add_column :name => 'length',       :pos => 5, :aggregator => :average,   :conversion => :integer
      add_column :name => 'length_by_ip', :pos => 5, :aggregator => :average,   :conversion => :integer, :group_by => 'ip'

      def time
        Time.strptime(self.timestamp, '%d/%b/%Y:%H:%M:%S %z')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logfile_interval-1.1.0 spec/support/lib/access_log.rb