Class: NewRelic::Agent::Samplers::DelayedJobSampler

Inherits:
NewRelic::Agent::Sampler show all
Defined in:
lib/new_relic/agent/samplers/delayed_job_sampler.rb

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.

Instance Attribute Summary

Attributes inherited from NewRelic::Agent::Sampler

#id, #stats_engine

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NewRelic::Agent::Sampler

inherited, sampler_classes, use_harvest_sampler?

Constructor Details

#initializeDelayedJobSampler

Returns a new instance of DelayedJobSampler.

Raises:



19
20
21
22
23
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 19

def initialize
  super :delayed_job_queue
  raise Unsupported, "DJ instrumentation disabled" if Agent.config[:disable_dj]
  raise Unsupported, "No DJ worker present" unless NewRelic::DelayedJobInjection.worker_name
end

Class Method Details

.supported_on_this_platform?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 48

def self.supported_on_this_platform?
  defined?(Delayed::Job)
end

Instance Method Details

#failed_jobsObject



41
42
43
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 41

def failed_jobs
  Delayed::Job.count(:conditions => 'failed_at is not NULL')
end

#local_envObject



33
34
35
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 33

def local_env
  NewRelic::Control.instance.local_env
end

#locked_jobsObject



44
45
46
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 44

def locked_jobs
  Delayed::Job.count(:conditions => 'locked_by is not NULL')
end

#pollObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 52

def poll
  record_failed_jobs(failed_jobs)
  record_locked_jobs(locked_jobs)

  if @queue
    record_queue_length_across_dimension('queue')
  else
    record_queue_length_across_dimension('priority')
  end
end

#record_failed_jobs(value) ⇒ Object



25
26
27
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 25

def record_failed_jobs(value)
  NewRelic::Agent.record_metric("Workers/DelayedJob/failed_jobs", value)
end

#record_locked_jobs(value) ⇒ Object



29
30
31
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 29

def record_locked_jobs(value)
  NewRelic::Agent.record_metric("Workers/DelayedJob/locked_jobs", value)
end

#worker_nameObject



37
38
39
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 37

def worker_name
  local_env.dispatcher_instance_id
end