Class: RedisDashboard::Client
- Inherits:
-
Object
- Object
- RedisDashboard::Client
- Defined in:
- lib/redis_dashboard/client.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #clients ⇒ Object
- #close ⇒ Object
- #config ⇒ Object
- #info ⇒ Object
-
#initialize(url) ⇒ Client
constructor
A new instance of Client.
- #memory_stats ⇒ Object
- #slow_commands ⇒ Object
- #stats ⇒ Object
Constructor Details
#initialize(url) ⇒ Client
Returns a new instance of Client.
4 5 6 |
# File 'lib/redis_dashboard/client.rb', line 4 def initialize(url) @url = url end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
2 3 4 |
# File 'lib/redis_dashboard/client.rb', line 2 def url @url end |
Instance Method Details
#clients ⇒ Object
8 9 10 |
# File 'lib/redis_dashboard/client.rb', line 8 def clients connection.client("list") end |
#close ⇒ Object
42 43 44 |
# File 'lib/redis_dashboard/client.rb', line 42 def close connection.close if connection end |
#config ⇒ Object
12 13 14 |
# File 'lib/redis_dashboard/client.rb', line 12 def config array_reply_to_hash(connection.config("get", "*")) end |
#info ⇒ Object
16 17 18 |
# File 'lib/redis_dashboard/client.rb', line 16 def info connection.info end |
#memory_stats ⇒ Object
38 39 40 |
# File 'lib/redis_dashboard/client.rb', line 38 def memory_stats array_reply_to_hash(connection.memory("stats")) end |
#slow_commands ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/redis_dashboard/client.rb', line 27 def slow_commands connection.slowlog("get", config["slowlog-max-len"]).map do |entry| cmd = RedisDashboard::Command.new cmd.id = entry[0] cmd. = entry[1] cmd.microseconds = entry[2] cmd.command = entry[3] cmd end.sort{ |left, right| right.microseconds <=> left.microseconds } end |
#stats ⇒ Object
20 21 22 23 24 25 |
# File 'lib/redis_dashboard/client.rb', line 20 def stats stats = connection.info("commandstats").sort { |a, b| b.last["usec"].to_i <=> a.last["usec"].to_i } total = stats.reduce(0) { |total, stat| total += stat.last["usec"].to_i } stats.each { |stat| stat.last["impact"] = stat.last["usec"].to_f * 100 / total } stats end |