Skip to content

Instantly share code, notes, and snippets.

@elmer
Forked from mattetti/gist:3473008
Created August 26, 2012 12:56
Show Gist options
  • Save elmer/3478834 to your computer and use it in GitHub Desktop.
Save elmer/3478834 to your computer and use it in GitHub Desktop.
Redis instrumentation
::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