Class: PrometheusExporter::Instrumentation::SidekiqQueue
- Inherits:
-
Object
- Object
- PrometheusExporter::Instrumentation::SidekiqQueue
- Defined in:
- lib/prometheus_exporter/instrumentation/sidekiq_queue.rb
Class Method Summary collapse
Instance Method Summary collapse
- #collect ⇒ Object
- #collect_queue_stats ⇒ Object
-
#initialize(all_queues: false) ⇒ SidekiqQueue
constructor
A new instance of SidekiqQueue.
Constructor Details
#initialize(all_queues: false) ⇒ SidekiqQueue
Returns a new instance of SidekiqQueue.
22 23 24 25 26 |
# File 'lib/prometheus_exporter/instrumentation/sidekiq_queue.rb', line 22 def initialize(all_queues: false) @all_queues = all_queues @pid = ::Process.pid @hostname = Socket.gethostname end |
Class Method Details
.start(client: nil, frequency: 30, all_queues: false) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/prometheus_exporter/instrumentation/sidekiq_queue.rb', line 5 def self.start(client: nil, frequency: 30, all_queues: false) client ||= PrometheusExporter::Client.default sidekiq_queue_collector = new(all_queues: all_queues) Thread.new do loop do begin client.send_json(sidekiq_queue_collector.collect) rescue StandardError => e client.logger.error("Prometheus Exporter Failed To Collect Sidekiq Queue metrics #{e}") ensure sleep frequency end end end end |
Instance Method Details
#collect ⇒ Object
28 29 30 31 32 33 |
# File 'lib/prometheus_exporter/instrumentation/sidekiq_queue.rb', line 28 def collect { type: 'sidekiq_queue', queues: collect_queue_stats } end |
#collect_queue_stats ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/prometheus_exporter/instrumentation/sidekiq_queue.rb', line 35 def collect_queue_stats sidekiq_queues = ::Sidekiq::Queue.all unless @all_queues queues = collect_current_process_queues sidekiq_queues.select! { |sidekiq_queue| queues.include?(sidekiq_queue.name) } end sidekiq_queues.map do |queue| { backlog: queue.size, latency_seconds: queue.latency.to_i, labels: { queue: queue.name } } end.compact end |