Skip to content

Instantly share code, notes, and snippets.

@bohford
Created July 14, 2011 08:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bohford/1082107 to your computer and use it in GitHub Desktop.
Save bohford/1082107 to your computer and use it in GitHub Desktop.
Redis monitor log parser
# redis-cli monitor > log.redis
puts "Scanning redis log..."
ops = Hash.new(0)
lines = File.readlines('log.redis'); true
start_time = Time.at(lines[1].split(' ').first.to_f)
end_time = Time.at(lines.last.split(' ').first.to_f)
time_elapsed = end_time - start_time
rps = (lines.count-1)/time_elapsed
puts "#{time_elapsed}s elapsed"
puts "#{rps} requests per second"
lines.each do |n|
next unless n =~ /"([^"]+)" "([^"]+)"/ # only get commands
op = $1
key = $2
key = key.gsub(/\d+/,"n")
ops["#{op.upcase} #{key}"]+=1
end; true
ops.sort_by{|(a,b)| b}.reverse[0..50].each do |(opkey, count)|
puts "#{count} #{opkey}"
end; true
@paramaggarwal
Copy link

this is very useful - thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment