Created
July 14, 2011 08:40
-
-
Save bohford/1082107 to your computer and use it in GitHub Desktop.
Redis monitor log parser
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is very useful - thanks! 🎉