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:



15
16
17
18
19
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 15

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)


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

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

Instance Method Details

#error_statsObject



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

def error_stats
  stats_engine.get_stats("Workers/DelayedJob/failed_jobs", false)
end

#failed_jobsObject



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

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

#local_envObject



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

def local_env
  NewRelic::Control.instance.local_env
end

#locked_job_statsObject



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

def locked_job_stats
  stats_engine.get_stats("Workers/DelayedJob/locked_jobs", false)
end

#locked_jobsObject



39
40
41
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 39

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

#pollObject



47
48
49
50
51
52
53
54
55
56
# File 'lib/new_relic/agent/samplers/delayed_job_sampler.rb', line 47

def poll
  record error_stats, failed_jobs
  record locked_job_stats, locked_jobs

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

#worker_nameObject



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

def worker_name
  local_env.dispatcher_instance_id
end