Sha256: c67789186783d2f61df482dea2e8eae062dad36908616a47a29d92de5a6c819a

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module PrometheusExporter::Instrumentation
  class SidekiqProcess < PeriodicStats
    def self.start(client: nil, frequency: 30)
      client ||= PrometheusExporter::Client.default
      sidekiq_process_collector = new

      worker_loop do
        client.send_json(sidekiq_process_collector.collect)
      end

      super
    end

    def initialize
      @pid = ::Process.pid
      @hostname = Socket.gethostname
    end

    def collect
      {
        type: 'sidekiq_process',
        process: collect_stats
      }
    end

    def collect_stats
      process = current_process
      return {} unless process

      {
        busy: process['busy'],
        concurrency: process['concurrency'],
        labels: {
          labels: process['labels'].sort.join(','),
          queues: process['queues'].sort.join(','),
          quiet: process['quiet'],
          tag: process['tag'],
          hostname: process['hostname'],
          identity: process['identity'],
        }
      }
    end

    def current_process
      ::Sidekiq::ProcessSet.new.find do |sp|
        sp['hostname'] == @hostname && sp['pid'] == @pid
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
prometheus_exporter-2.1.1 lib/prometheus_exporter/instrumentation/sidekiq_process.rb
prometheus_exporter-2.1.0 lib/prometheus_exporter/instrumentation/sidekiq_process.rb
prometheus_exporter-2.0.8 lib/prometheus_exporter/instrumentation/sidekiq_process.rb
prometheus_exporter-2.0.7 lib/prometheus_exporter/instrumentation/sidekiq_process.rb
prometheus_exporter-2.0.6 lib/prometheus_exporter/instrumentation/sidekiq_process.rb
prometheus_exporter-2.0.5 lib/prometheus_exporter/instrumentation/sidekiq_process.rb
prometheus_exporter-2.0.4 lib/prometheus_exporter/instrumentation/sidekiq_process.rb
prometheus_exporter-2.0.3 lib/prometheus_exporter/instrumentation/sidekiq_process.rb
prometheus_exporter-2.0.2 lib/prometheus_exporter/instrumentation/sidekiq_process.rb
prometheus_exporter-2.0.1 lib/prometheus_exporter/instrumentation/sidekiq_process.rb