Skip to content

Instantly share code, notes, and snippets.

@mk-qi
Created January 3, 2014 07:41
Show Gist options
  • Save mk-qi/8234333 to your computer and use it in GitHub Desktop.
Save mk-qi/8234333 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'redis'
require 'terminal-table'
host = "192.168.2.164"
ports = [6381]
def entries(slowlog)
sort(slowlog).map do |entry|
[
id = entry.shift,
logtime = Time.at(entry.shift),
us = entry.shift/1000000.000,
cmd = entry.shift.join(' ')[0...100]
]
end
end
def sort(slowlog)
slowlog.sort_by{|a| a[2]}.reverse!
end
ports.each do |port|
redis = Redis.new(:host => host, :port => port)
slowlog = entries(redis.slowlog("GET",50))
table = Terminal::Table.new :title => "Redis SlowLog for Redis data.redis1.51fanli.it:#{port}", :headings => ['ID', 'logtime', 'time', 'cmd'], :rows => slowlog
puts table
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment