-
-
Save elmer/3478834 to your computer and use it in GitHub Desktop.
Redis instrumentation
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
::Redis::Client.class_eval do | |
# Support older versions of Redis::Client that used the method | |
# +raw_call_command+. | |
call_method = ::Redis::Client.new.respond_to?(:call) ? :call : :raw_call_command | |
def call_with_stats_trace(*args, &blk) | |
method_name = args[0].is_a?(Array) ? args[0][0] : args[0] | |
start = Time.now | |
begin | |
call_without_stats_trace(*args, &blk) | |
ensure | |
METRICS.timing("#{Thread.current[:stats_context] || 'wild'}.redis.#{method_name.to_s.upcase}.query_time", | |
((Time.now - start) * 1000).round, 1) rescue nil | |
end | |
end | |
alias_method :call_without_stats_trace, call_method | |
alias_method call_method, :call_with_stats_trace | |
end if defined?(::Redis::Client) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment