11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/metrician/reporters/redis.rb', line 11
def instrument
return if ::Redis::Client.method_defined?(:call_with_metrician_time)
::Redis::Client.class_eval do
def call_with_metrician_time(*args, &blk)
start_time = Time.now
begin
call_without_metrician_time(*args, &blk)
ensure
duration = (Time.now - start_time).to_f
Metrician.gauge(CACHE_METRIC, duration) if Metrician.configuration[:cache][:command][:enabled]
if Metrician.configuration[:cache][:command_specific][:enabled]
method_name = args[0].is_a?(Array) ? args[0][0] : args[0]
Metrician.gauge("#{CACHE_METRIC}.#{method_name}", duration)
end
end
end
alias_method :call_without_metrician_time, :call
alias_method :call, :call_with_metrician_time
end
end
|