Skip to content

Commit

Permalink
Merge pull request #20 from mokpro/worker_tags
Browse files Browse the repository at this point in the history
create a private tags method that can be overridden by the app
  • Loading branch information
mokpro authored Feb 3, 2023
2 parents 8e50a13 + c11c224 commit c39b255
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/sidekiq/instrument/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Sidekiq
module Instrument
VERSION = "0.5.4"
VERSION = '0.5.5'
end
end
36 changes: 27 additions & 9 deletions lib/sidekiq/instrument/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class Worker
# (i.e. the metrics will reported as :processed, :workers, :pending, and :failed).
# Feel free to override.
METRIC_NAMES = {
processed: nil,
processed: nil,
workers_size: :workers,
enqueued: :pending,
failed: nil
enqueued: :pending,
failed: nil
}

def perform
Expand All @@ -29,17 +29,35 @@ def perform
Statter.statsd.gauge('shared.sidekiq.stats.working', working)
Statter.dogstatsd&.gauge('sidekiq.working', working)

info.queues.each do |name, size|
Statter.statsd.gauge("shared.sidekiq.#{name}.size", size)
Statter.dogstatsd&.gauge('sidekiq.queue.size', size, tags: ["queue:#{name}"])
end

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: ["queue:#{queue.name}"])
Statter.dogstatsd&.gauge('sidekiq.queue.latency', queue.latency, tags: dd_tags(queue))
end

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

private

# @param [Sidekiq::Queue] queue used for stats emission
# @return [Array<String>] an array of tags
# @example this method can be override to add more tags
# class MyStatsWorker < Sidekiq::Instrument::Worker
# private
#
# def dd_tags(queue)
# custom_tags = []
# queue_type = queue.name.match?(/readonly$/) ? 'read_only' : 'regular'
# custom_tags << "queue_type:#{queue_type}"
#
# super(queue) | custom_tags
# end
# end
def dd_tags(queue)
["queue:#{queue.name}"]
end
end
end

0 comments on commit c39b255

Please sign in to comment.