Class: NewRelic::Agent::Samplers::SidekiqSampler

Inherits:
NewRelic::Agent::Sampler
  • Object
show all
Defined in:
lib/newrelic-sidekiq-stats.rb

Constant Summary collapse

METRIC_MAP =
{
  processed:      'ProcessedSize',
  failed:         'FailedSize',
  scheduled_size: 'ScheduledSize',
  retry_size:     'RetrySize',
  dead_size:      'DeadSize',
  enqueued:       'EnqueuedSize',
  processes_size: 'ProcessesSize',
  workers_size:   'WorkersSize',
}.freeze

Instance Method Summary collapse

Instance Method Details

#pollObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/newrelic-sidekiq-stats.rb', line 20

def poll
  return unless Sidekiq.server?

  stats       = Sidekiq::Stats.new
  max_latency = Sidekiq::Queue.all.map(&:latency).max
  ::NewRelic::Agent.logger.debug("Recording metric: Custom/Sidekiq/QueueLatency=#{max_latency}")
  ::NewRelic::Agent.record_metric("Custom/Sidekiq/QueueLatency", max_latency)
  METRIC_MAP.map do |key, name|
    value = stats.public_send(key)
    ::NewRelic::Agent.logger.debug("Recording metric: Custom/Sidekiq/#{name}=#{value}")
    ::NewRelic::Agent.record_metric("Custom/Sidekiq/#{name}", value)
  end
end