Skip to content

Instantly share code, notes, and snippets.

@dcampano
Created March 20, 2010 14:43
Show Gist options
  • Save dcampano/338702 to your computer and use it in GitHub Desktop.
Save dcampano/338702 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
def print_responses(times)
%w{ 0.95 0.99 0.995 0.999 }.each do |percentile|
pos = (percentile.to_f * times.length).floor
p pos.to_s + ": " + times[pos].to_s
end
end
num = 0
rows_to_process = 1000000
times = []
IO.popen("tail -n #{rows_to_process} /opt/nginx/logs/upstream.log | grep -v lobby.php"){|f|
while line = f.gets
response_time = line.split(' ')[0].to_f
times.push response_time
#p response_time
num = num + 1
break if num > rows_to_process
end
}
times.sort!
print_responses times
p "finished"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment