forked from take-five/rack-bug
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request brynary#9 from oggy/redis
AJAX support for redis panel
- Loading branch information
Showing
3 changed files
with
35 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,47 @@ | ||
module Rack::Insight | ||
|
||
class RedisPanel < Panel | ||
require "rack/insight/panels/redis_panel/redis_extension" | ||
|
||
require "rack/insight/panels/redis_panel/stats" | ||
|
||
self.has_table = false | ||
|
||
def self.record(redis_command_args, backtrace, &block) | ||
return block.call unless Rack::Insight.enabled? | ||
|
||
start_time = Time.now | ||
result = block.call | ||
total_time = Time.now - start_time | ||
stats.record_call(total_time * 1_000, redis_command_args, backtrace) | ||
return result | ||
def initialize(app) | ||
super | ||
|
||
unless is_probing? | ||
probe(self) do | ||
if defined?(Redis::Client) | ||
# Redis >= 3.0.0 | ||
instrument "Redis::Client" do | ||
instance_probe :call | ||
end | ||
elsif defined?(Redis) | ||
# Redis < 3.0.0 | ||
instrument "Redis" do | ||
instance_probe :call_command | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
def self.reset | ||
Thread.current["rack-insight.redis"] = Stats.new | ||
def request_start(env, start) | ||
@stats = Stats.new | ||
end | ||
|
||
def self.stats | ||
Thread.current["rack-insight.redis"] ||= Stats.new | ||
def request_finish(env, status, headers, body, timing) | ||
store(env, @stats) | ||
@stats = nil | ||
end | ||
|
||
def heading | ||
"Redis: %.2fms (#{self.class.stats.queries.size} calls)" % self.class.stats.time | ||
def after_detect(method_call, timing, args, message) | ||
@stats.record_call(timing.duration, args, method_call) | ||
end | ||
|
||
def content | ||
result = render_template "panels/redis", :stats => self.class.stats | ||
self.class.reset | ||
return result | ||
def heading_for_request(number) | ||
stats = retrieve(number).first | ||
"Redis: %.2fms (#{stats.queries.size} calls)" % stats.time | ||
end | ||
|
||
def content_for_request(number) | ||
render_template "panels/redis", :stats => retrieve(number).first | ||
end | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
This file contains 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