Skip to content

Instantly share code, notes, and snippets.

@carlwoodward
Created August 30, 2009 01:49
Show Gist options
  • Select an option

  • Save carlwoodward/177817 to your computer and use it in GitHub Desktop.

Select an option

Save carlwoodward/177817 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'apachelogregex'
require 'ostruct'
@requests = {}
def to_date(d)
Date.strptime d.gsub('[', '').gsub(']', ''), "%d/%b/%Y"
end
def add_request(ip, line)
key = ip
if @requests.key?(key)
@requests[key] << line
else
@requests[key] = [line]
end
end
def page?(l)
%w(.css .js .json .gif .png .jpg .pdf .swf).detect {|ext| l.include?(ext)}.nil?
end
format = '%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"'
parser = ApacheLogRegex.new format
file = File.new 'rsff-files-only.log'
key = nil
bounces = 0
request_count = 0
while file.gets
line = parser.parse($_)
if line
if key.nil? or key != line['%h']
if request_count == 1
bounces += 1
puts "bounce"
end
key = line['%h']
request_count = 1
else
request_count += 1
end
end
end
puts "BOUNCES #{bounces}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment