Sha256: a18fc4ee262396452f28ced9316341d26252e0b55e0fd6e8407465d95f37ae49

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

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_total] = info[:processed]
      metric[:failed_jobs_total] = info[:failed]
      metric[:pending_jobs_total] = info[:pending]
      metric[:queues_total] = info[:queues]
      metric[:worker_total] = info[:workers]
      metric[:working_total] = info[:working]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prometheus_exporter-0.8.1 lib/prometheus_exporter/instrumentation/resque.rb