skylight: extract probes from config.ru
This commit is contained in:
parent
928ed11c62
commit
162b5b0cca
46
config.ru
46
config.ru
|
@ -30,51 +30,5 @@ class RackTimer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if ENV['SKYLIGHT_APPLICATION']
|
|
||||||
require 'skylight'
|
|
||||||
|
|
||||||
class DalliProbe
|
|
||||||
def install
|
|
||||||
%w[get get_multi set add incr decr delete replace append prepend].each do |method_name|
|
|
||||||
next unless Dalli::Client.method_defined?(method_name.to_sym)
|
|
||||||
Dalli::Client.class_eval <<-EOD
|
|
||||||
alias #{method_name}_without_sk #{method_name}
|
|
||||||
def #{method_name}(*args, &block)
|
|
||||||
Skylight.instrument(category: "api.memcache.#{method_name}", title: "Memcache #{method_name}") do
|
|
||||||
#{method_name}_without_sk(*args, &block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
EOD
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Skylight::Probes.register("Dalli::Client", "dalli", DalliProbe.new)
|
|
||||||
|
|
||||||
class RedisProbe
|
|
||||||
def install
|
|
||||||
::Redis::Client.class_eval do
|
|
||||||
alias call_without_sk call
|
|
||||||
|
|
||||||
def call(command_parts, &block)
|
|
||||||
command = command_parts[0].upcase
|
|
||||||
|
|
||||||
opts = {
|
|
||||||
category: "api.redis.#{command.downcase}",
|
|
||||||
title: "Redis #{command}",
|
|
||||||
annotations: {
|
|
||||||
command: command.to_s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Skylight.instrument(opts) do
|
|
||||||
call_without_sk(command_parts, &block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Skylight::Probes.register("Redis", "redis", RedisProbe.new)
|
|
||||||
end
|
|
||||||
|
|
||||||
use RackTimer
|
use RackTimer
|
||||||
run Travis::Api::App.new
|
run Travis::Api::App.new
|
||||||
|
|
|
@ -9,7 +9,9 @@ class Travis::Api::App
|
||||||
|
|
||||||
if ENV['SKYLIGHT_APPLICATION']
|
if ENV['SKYLIGHT_APPLICATION']
|
||||||
require 'skylight'
|
require 'skylight'
|
||||||
register Skylight::Sinatra
|
require 'travis/api/app/skylight/dalli_probe'
|
||||||
|
require 'travis/api/app/skylight/redis_probe'
|
||||||
|
register ::Skylight::Sinatra
|
||||||
end
|
end
|
||||||
|
|
||||||
error NotImplementedError do
|
error NotImplementedError do
|
||||||
|
|
24
lib/travis/api/app/skylight/dalli_probe.rb
Normal file
24
lib/travis/api/app/skylight/dalli_probe.rb
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
require 'skylight'
|
||||||
|
require 'travis/api/app'
|
||||||
|
|
||||||
|
class Travis::Api::App
|
||||||
|
module Skylight
|
||||||
|
class DalliProbe
|
||||||
|
def install
|
||||||
|
%w[get get_multi set add incr decr delete replace append prepend].each do |method_name|
|
||||||
|
next unless Dalli::Client.method_defined?(method_name.to_sym)
|
||||||
|
Dalli::Client.class_eval <<-EOD
|
||||||
|
alias #{method_name}_without_sk #{method_name}
|
||||||
|
def #{method_name}(*args, &block)
|
||||||
|
::Skylight.instrument(category: "api.memcache.#{method_name}", title: "Memcache #{method_name}") do
|
||||||
|
#{method_name}_without_sk(*args, &block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
EOD
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
::Skylight::Probes.register("Dalli::Client", "dalli", DalliProbe.new)
|
||||||
|
end
|
||||||
|
end
|
31
lib/travis/api/app/skylight/redis_probe.rb
Normal file
31
lib/travis/api/app/skylight/redis_probe.rb
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
require 'skylight'
|
||||||
|
require 'travis/api/app'
|
||||||
|
|
||||||
|
class Travis::Api::App
|
||||||
|
module Skylight
|
||||||
|
class RedisProbe
|
||||||
|
def install
|
||||||
|
::Redis::Client.class_eval do
|
||||||
|
alias call_without_sk call
|
||||||
|
|
||||||
|
def call(command_parts, &block)
|
||||||
|
command = command_parts[0].upcase
|
||||||
|
|
||||||
|
opts = {
|
||||||
|
category: "api.redis.#{command.downcase}",
|
||||||
|
title: "Redis #{command}",
|
||||||
|
annotations: {
|
||||||
|
command: command.to_s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
::Skylight.instrument(opts) do
|
||||||
|
call_without_sk(command_parts, &block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
::Skylight::Probes.register("Redis", "redis", RedisProbe.new)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user