Class: NewRelic::Agent::Samplers::DelayedJobSampler
Overview
This sampler records the status of your delayed job table once a minute. It assumes jobs are cleared after being run, and failed jobs are not (otherwise the failed job metric is useless).
In earlier versions it will break out the queue length by priority. In later versions of DJ where distinct queues are supported, it breaks it out by queue name.
Constant Summary
collapse
- FAILED_QUERY =
'failed_at is not NULL'.freeze
- LOCKED_QUERY =
'locked_by is not NULL'.freeze
Instance Attribute Summary
#id
Class Method Summary
collapse
Instance Method Summary
collapse
enabled?, inherited, named, sampler_classes
Constructor Details
Returns a new instance of DelayedJobSampler.
[View source]
27
28
29
30
31
|
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 27
def initialize
raise Unsupported, 'DJ queue sampler disabled' if Agent.config[:'instrumentation.delayed_job'] == 'disabled'
raise Unsupported, "DJ queue sampling unsupported with backend '#{::Delayed::Worker.backend}'" unless self.class.supported_backend?
raise Unsupported, 'No DJ worker present. Skipping DJ queue sampler' unless NewRelic::DelayedJobInjection.worker_name
end
|
Class Method Details
permalink
.supported_backend? ⇒ Boolean
DelayedJob supports multiple backends, only some of which we can handle. Check whether we think we’ve got what we need here.
[View source]
23
24
25
|
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 23
def self.supported_backend?
::Delayed::Worker.backend.to_s == 'Delayed::Backend::ActiveRecord::Job'
end
|
[View source]
60
61
62
|
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 60
def self.supported_on_this_platform?
defined?(::Delayed::Job)
end
|
Instance Method Details
permalink
#count(query) ⇒ Object
[View source]
52
53
54
55
56
57
58
|
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 52
def count(query)
if ::ActiveRecord::VERSION::MAJOR.to_i < 4
::Delayed::Job.count(:conditions => query)
else
::Delayed::Job.where(query).count
end
end
|
permalink
#failed_jobs ⇒ Object
[View source]
44
45
46
|
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 44
def failed_jobs
count(FAILED_QUERY)
end
|
permalink
#locked_jobs ⇒ Object
[View source]
48
49
50
|
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 48
def locked_jobs
count(LOCKED_QUERY)
end
|
[View source]
64
65
66
67
68
69
70
71
|
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 64
def poll
ActiveRecord::Base.connection_pool.with_connection do
record_failed_jobs(failed_jobs)
record_locked_jobs(locked_jobs)
record_queue_length_metrics
end
end
|
permalink
#record_failed_jobs(value) ⇒ Object
[View source]
33
34
35
|
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 33
def record_failed_jobs(value)
NewRelic::Agent.record_metric('Workers/DelayedJob/failed_jobs', value)
end
|
permalink
#record_locked_jobs(value) ⇒ Object
[View source]
37
38
39
|
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 37
def record_locked_jobs(value)
NewRelic::Agent.record_metric('Workers/DelayedJob/locked_jobs', value)
end
|