Class: Sidekiq::Instrument::Worker

Inherits:
Object
  • Object
show all
Includes:
Worker
Defined in:
lib/sidekiq/instrument/worker.rb

Constant Summary collapse

METRIC_NAMES =

These defaults are for compatibility with Resque’s stats names (i.e. the metrics will reported as :processed, :workers, :pending, and :failed). Feel free to override.

{
  processed: nil,
  workers_size: :workers,
  enqueued: :pending,
  failed: nil
}.freeze

Instance Method Summary collapse

Instance Method Details

#performObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sidekiq/instrument/worker.rb', line 20

def perform
  info = Sidekiq::Stats.new

  self.class::METRIC_NAMES.each do |method, stat|
    stat ||= method

    Statter.statsd.gauge("shared.sidekiq.stats.#{stat}", info.send(method))
    Statter.dogstatsd&.gauge("sidekiq.#{stat}", info.send(method))
  end

  working = Sidekiq::Workers.new.count
  Statter.statsd.gauge('shared.sidekiq.stats.working', working)
  Statter.dogstatsd&.gauge('sidekiq.working', working)
  send_worker_metrics
  Sidekiq::Queue.all.each do |queue|
    Statter.statsd.gauge("shared.sidekiq.#{queue.name}.size", queue.size)
    Statter.dogstatsd&.gauge('sidekiq.queue.size', queue.size, tags: dd_tags(queue))

    Statter.statsd.gauge("shared.sidekiq.#{queue.name}.latency", queue.latency)
    Statter.dogstatsd&.gauge('sidekiq.queue.latency', queue.latency, tags: dd_tags(queue))
  end

  Statter.dogstatsd&.flush(sync: true)
end