Skip to content

Instantly share code, notes, and snippets.

@paramaggarwal
Forked from bohford/redis_monitor_parser.rb
Last active May 15, 2021 14:45
Show Gist options
  • Save paramaggarwal/b20b1ce8e1d43b7684424ac4714a76dd to your computer and use it in GitHub Desktop.
Save paramaggarwal/b20b1ce8e1d43b7684424ac4714a76dd to your computer and use it in GitHub Desktop.
Redis monitor log parser
# 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