-
-
Save paramaggarwal/b20b1ce8e1d43b7684424ac4714a76dd 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 > monitor.txt | |
puts "Scanning redis log..." | |
ops = Hash.new(0) | |
lines = File.readlines('monitor.txt'); 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..20].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