Sha256: ba2166e0f24889946417c2407b89e57cd17f1d955ca563b2fc69c78d84050ebe

Contents?: true

Size: 984 Bytes

Versions: 1

Compression:

Stored size: 984 Bytes

Contents

# frozen_string_literal: true

require 'sidekiq/api'

module Sidekiq
  module Prometheus
    class Metrics
      QueueStats = Struct.new(:name, :size, :latency)

      def initialize
        @overview_stats = Sidekiq::Stats.new
        @queues_stats = queues_stats
        @max_processing_times = max_processing_times
      end

      def __binding__
        binding
      end

      private

      def queues_stats
        Sidekiq::Queue.all.map do |queue|
          QueueStats.new(queue.name, queue.size, queue.latency)
        end
      end

      def max_processing_times
        now = Time.now.to_i
        Sidekiq::Workers.new
          .map { |_, _, execution| execution }
          .group_by { |execution| execution['queue'] }
          .each_with_object({}) do |(queue, executions), memo|
            oldest_execution = executions.min_by { |execution| execution['run_at'] }
            memo[queue] = now - oldest_execution['run_at']
          end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-prometheus-exporter-0.1.7 lib/sidekiq/prometheus/exporter/metrics.rb