Skip to content

Instantly share code, notes, and snippets.

@kcdragon
Created August 29, 2016 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcdragon/5374200155ea86e6cad9035d215d923a to your computer and use it in GitHub Desktop.
Save kcdragon/5374200155ea86e6cad9035d215d923a to your computer and use it in GitHub Desktop.
Joins Rails logs produced on different app servers
require 'pp'
by_ip = {}
DATA.each_line do |line|
request = line.split(' ')
url = request[1] + ' ' + request[2].gsub('"', '')
ip = request[4]
by_ip[ip] ||= []
by_ip[ip] << url
end
pp by_ip
puts "total #{by_ip.size}"
sum = 0
by_ip.each do |ip, history|
add = 0
history.each_cons(2) do |(first, second)|
if first.end_with?('/checkout/place_order') && second.end_with?('/checkout/confirmation')
add = 1
end
end
sum += add
end
puts sum
sum = 0
addresses = []
histories = []
by_ip.each do |ip, history|
add = 0
history.each_cons(2) do |(first, second)|
if first.end_with?('/checkout/place_order') && second.end_with?('/checkout')
add = 1
addresses << ip
histories << [ip, history]
end
end
sum += add
end
puts sum
puts addresses
histories.each do |h|
puts h
puts
end
__END__
Started GET "/checkout" for 11.222.333.444 at 2014-05-22 06:28:59 -0400
Started POST "/checkout" for 11.222.333.444 at 2014-05-22 06:29:02 -0400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment