Module: Metrician
- Defined in:
- lib/metrician/jobs/resque_plugin.rb,
lib/metrician.rb,
lib/metrician/jobs.rb,
lib/metrician/version.rb,
lib/metrician/reporter.rb,
lib/metrician/middleware.rb,
lib/metrician/configuration.rb,
lib/metrician/reporters/redis.rb,
lib/metrician/reporters/resque.rb,
lib/metrician/reporters/sidekiq.rb,
lib/metrician/reporters/memcache.rb,
lib/metrician/reporters/net_http.rb,
lib/metrician/reporters/middleware.rb,
lib/metrician/reporters/delayed_job.rb,
lib/metrician/reporters/honeybadger.rb,
lib/metrician/reporters/method_timer.rb,
lib/metrician/jobs/sidekiq_middleware.rb,
lib/metrician/reporters/active_record.rb,
lib/metrician/middleware/request_timing.rb,
lib/metrician/jobs/delayed_job_callbacks.rb,
lib/metrician/middleware/application_timing.rb
Overview
Defined Under Namespace
Modules: Jobs, Middleware, QueryInterceptor, Reporters, TimingMethodInterceptor
Classes: ActiveRecord, Configuration, DelayedJob, Honeybadger, Memcache, MethodTimer, NetHttp, Redis, Reporter, Resque, Sidekiq
Constant Summary
collapse
- AgentNotInitialized =
Class.new(StandardError)
- MissingAgent =
Class.new(ArgumentError)
- IncompatibleAgent =
Class.new(ArgumentError)
- REQUIRED_AGENT_METHODS =
[
:cleanup,
:gauge,
:increment,
:logger,
"logger=".to_sym,
]
- DEFAULT_PREFIX =
"app.".freeze
- VERSION =
"0.1.0".freeze
Class Method Summary
collapse
Class Method Details
.activate(agent) ⇒ Object
23
24
25
26
|
# File 'lib/metrician.rb', line 23
def self.activate(agent)
self.agent = agent
Metrician::Reporter.all.each(&:instrument)
end
|
.agent ⇒ Object
40
41
42
|
# File 'lib/metrician.rb', line 40
def self.agent
@agent || raise(AgentNotInitialized.new)
end
|
.agent=(agent) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/metrician.rb', line 28
def self.agent=(agent)
if agent.nil?
raise MissingAgent.new
end
REQUIRED_AGENT_METHODS.each do |method|
raise IncompatibleAgent.new("agent must implement #{method}") unless agent.respond_to?(method)
end
@agent = agent
end
|
.dotify(klass) ⇒ Object
52
53
54
|
# File 'lib/metrician.rb', line 52
def self.dotify(klass)
klass.to_s.underscore.gsub(%r{/}, ".")
end
|
.gauge(metric, value) ⇒ Object
74
75
76
|
# File 'lib/metrician.rb', line 74
def self.gauge(metric, value)
prefixed? ? agent.gauge("#{prefix}#{metric}", value) : agent.gauge(metric, value)
end
|
.increment(metric, value = 1) ⇒ Object
69
70
71
|
# File 'lib/metrician.rb', line 69
def self.increment(metric, value = 1)
prefixed? ? agent.increment("#{prefix}#{metric}", value) : agent.increment(metric, value)
end
|
.logger ⇒ Object
48
49
50
|
# File 'lib/metrician.rb', line 48
def self.logger
agent.logger
end
|
.logger=(logger) ⇒ Object
44
45
46
|
# File 'lib/metrician.rb', line 44
def self.logger=(logger)
agent.logger = logger
end
|
.prefix ⇒ Object
61
62
63
|
# File 'lib/metrician.rb', line 61
def self.prefix
@prefix ||= DEFAULT_PREFIX
end
|
.prefix=(prefix) ⇒ Object
56
57
58
59
|
# File 'lib/metrician.rb', line 56
def self.prefix=(prefix)
@prefixed = nil
@prefix = prefix.to_s[-1] == "." ? prefix.to_s : "#{prefix}."
end
|
.prefixed? ⇒ Boolean
65
66
67
|
# File 'lib/metrician.rb', line 65
def self.prefixed?
@prefixed ||= !prefix.empty?
end
|
.reset ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/metrician.rb', line 82
def self.reset
%i[@agent @configuration].each do |memo_ivar|
if Metrician.instance_variable_defined?(memo_ivar)
Metrician.remove_instance_variable(memo_ivar)
end
end
end
|