Skip to content

Instantly share code, notes, and snippets.

@sumeet
Forked from joshuawscott/redis_slowlog.rb
Last active August 6, 2017 10:14
Show Gist options
  • Save sumeet/5763075e61ac408ee85dfaf6e5e8249c to your computer and use it in GitHub Desktop.
Save sumeet/5763075e61ac408ee85dfaf6e5e8249c to your computer and use it in GitHub Desktop.
Get Redis Slowlog Entries and parse them
require 'redis'
class Entry
attr_reader :log_number, :unix_timestamp, :microseconds, :command, :full_command
def initialize(raw_data)
@log_number = raw_data[0]
@unix_timestamp = raw_data[1]
@microseconds = raw_data[2]
@full_command = raw_data[4].join(' ')
end
def milliseconds
@microseconds / 1000.0
end
def time
Time.at @unix_timestamp
end
end
if ARGV.length < 1 || ARGV.length > 1
puts "redis_slowlog.rb <redis_url>"
exit
end
r = Redis.new url: ARGV[0]
data = r.slowlog :get
data.each do |raw_entry|
entry = Entry.new(raw_entry)
puts "#{entry.time}: #{entry.milliseconds}ms, #{entry.full_command}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment