Created
August 29, 2016 14:33
-
-
Save kcdragon/5374200155ea86e6cad9035d215d923a to your computer and use it in GitHub Desktop.
Joins Rails logs produced on different app servers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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