Created
June 9, 2015 20:04
-
-
Save timraymond/7f2bc55c4b0224527d22 to your computer and use it in GitHub Desktop.
Replay Heroku Logs
This file contains 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 'time' | |
require 'thread' | |
require 'uri' | |
require 'pry' | |
filename = ARGV.shift | |
if !filename | |
puts "Specify a filename" | |
exit(1) | |
end | |
queue = Queue.new | |
10.times do | |
Thread.new do | |
loop do | |
system queue.pop | |
end | |
end | |
end | |
lines = File.readlines(filename) | |
last_time = nil | |
ctr = 0 | |
lines.each do |line| | |
if line =~ /(?<=\s)([-\d:T\.\+]+)(?=\sheroku router)/ | |
time = DateTime.rfc3339($~.to_s).to_time | |
last_time ||= time | |
req_info = Hash[line.scan(/(?<=\s)(\w+)\=\"?(.+?)[\"|\s]/)] | |
if (req_info["dyno"] == "web.3" || req_info["dyno"] == "web.6") && req_info["method"] == "GET" | |
ctr += 1 | |
puts ctr if ctr % 10 == 0 | |
dt = (time.to_f-last_time.to_f).abs | |
uri = URI(ARGV.shift) | |
uri.path, _, uri.query = req_info["path"].partition("?") | |
uri.query = uri.query.split("&").tap { |q| q << "_token=#{ARGV.shift}" }.join("&") | |
fmt_path = req_info["path"].length > 50 ? req_info["path"][0..47] + "..." : req_info["path"] | |
puts "Delta-T: %1.2fs \tPath: %50s\tDyno: %5s" % [dt, fmt_path, req_info["dyno"]] | |
queue << "curl -s \"#{uri.to_s}\" > /dev/null" | |
last_time = time | |
sleep dt | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment