class Bigcommerce::Prometheus::Instrumentors::Resque

Instrumentors for resque process

Public Class Methods

new(app:) click to toggle source
# File lib/bigcommerce/prometheus/instrumentors/resque.rb, line 27
def initialize(app:)
  @app = app
  @enabled = Bigcommerce::Prometheus.enabled
  @process_name = Bigcommerce::Prometheus.process_name
  @server_port = Bigcommerce::Prometheus.server_port
  @server_timeout = Bigcommerce::Prometheus.server_timeout
  @server_prefix = Bigcommerce::Prometheus.server_prefix
  @collectors = Bigcommerce::Prometheus.resque_collectors || []
  @type_collectors = Bigcommerce::Prometheus.resque_type_collectors || []
end

Public Instance Methods

start() click to toggle source

Start the web instrumentor

# File lib/bigcommerce/prometheus/instrumentors/resque.rb, line 41
def start
  unless @enabled
    logger.debug "[bigcommerce-prometheus][#{@process_name}] Prometheus disabled, skipping resque start..."
    return
  end

  server.add_type_collector(PrometheusExporter::Server::ActiveRecordCollector.new)
  server.add_type_collector(Bigcommerce::Prometheus::TypeCollectors::Resque.new)
  @type_collectors.each do |tc|
    server.add_type_collector(tc)
  end
  server.start
  setup_middleware
rescue StandardError => e
  logger.error "[bigcommerce-prometheus][#{@process_name}] Failed to start resque instrumentation - #{e.message} - #{e.backtrace[0..4].join("\n")}"
end

Private Instance Methods

server() click to toggle source
# File lib/bigcommerce/prometheus/instrumentors/resque.rb, line 60
def server
  @server ||= ::Bigcommerce::Prometheus::Server.new(
    port: @server_port,
    timeout: @server_timeout,
    prefix: @server_prefix
  )
end
setup_middleware() click to toggle source
# File lib/bigcommerce/prometheus/instrumentors/resque.rb, line 68
def setup_middleware
  logger.info "[bigcommerce-prometheus][#{@process_name}] Setting up resque prometheus middleware"
  ::Resque.before_first_fork do
    ::Bigcommerce::Prometheus::Integrations::Resque.start(client: Bigcommerce::Prometheus.client)
    @collectors.each(&:start)
  end
end