Sha256: 9fa4ca71246e5399de8848a11096a0feac9dad35c403dfce065d8a602647acbf

Contents?: true

Size: 913 Bytes

Versions: 2

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true

module PrometheusExporter::Instrumentation
  class SidekiqQueue
    def self.start(client: nil, frequency: 30)
      client ||= PrometheusExporter::Client.default
      sidekiq_queue_collector = new

      Thread.new do
        loop do
          begin
            client.send_json(sidekiq_queue_collector.collect)
          rescue StandardError => e
            STDERR.puts("Prometheus Exporter Failed To Collect Sidekiq Queue metrics #{e}")
          ensure
            sleep frequency
          end
        end
      end
    end

    def collect
      {
        type: 'sidekiq_queue',
        queues: collect_queue_stats
      }
    end

    def collect_queue_stats
      ::Sidekiq::Queue.all.map do |queue|
        {
          backlog_total: queue.size,
          latency_seconds: queue.latency.to_i,
          labels: { queue: queue.name }
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
prometheus_exporter-0.5.3 lib/prometheus_exporter/instrumentation/sidekiq_queue.rb
prometheus_exporter-0.5.2 lib/prometheus_exporter/instrumentation/sidekiq_queue.rb