Sha256: edd948f70c9a6c5ec7605f8c01724cf7159fe84fbaa3ace37a2029701630e257

Contents?: true

Size: 1018 Bytes

Versions: 3

Compression:

Stored size: 1018 Bytes

Contents

# frozen_string_literal: true

# collects stats from resque
module PrometheusExporter::Instrumentation
  class Resque
    def self.start(client: nil, frequency: 30)
      resque_collector = new
      client ||= PrometheusExporter::Client.default
      Thread.new do
        while true
          begin
            client.send_json(resque_collector.collect)
          rescue => e
            client.logger.error("Prometheus Exporter Failed To Collect Resque Stats #{e}")
          ensure
            sleep frequency
          end
        end
      end
    end

    def collect
      metric = {}
      metric[:type] = "resque"
      collect_resque_stats(metric)
      metric
    end

    def collect_resque_stats(metric)
      info = ::Resque.info

      metric[:processed_jobs] = info[:processed]
      metric[:failed_jobs] = info[:failed]
      metric[:pending_jobs] = info[:pending]
      metric[:queues] = info[:queues]
      metric[:worker] = info[:workers]
      metric[:working] = info[:working]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
prometheus_exporter-2.0.0 lib/prometheus_exporter/instrumentation/resque.rb
prometheus_exporter-1.0.1 lib/prometheus_exporter/instrumentation/resque.rb
prometheus_exporter-1.0.0 lib/prometheus_exporter/instrumentation/resque.rb