Sha256: cf9eb6819a07b518e05f16f4f46546823aae12d976e53ffa86c33ca30bc1bbf4

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require 'sidekiq/api'
require 'newrelic_rpm'
require 'newrelic_sidekiq_metrics/version'
require 'newrelic_sidekiq_metrics/recorder'
require 'newrelic_sidekiq_metrics/middleware'

module NewrelicSidekiqMetrics
  METRIC_PREFIX = 'Custom/Sidekiq'.freeze

  METRIC_MAP = {
    processed:      'ProcessedSize',
    failed:         'FailedSize',
    scheduled_size: 'ScheduledSize',
    retry_size:     'RetrySize',
    dead_size:      'DeadSize',
    enqueued:       'EnqueuedSize',
    processes_size: 'ProcessesSize',
    workers_size:   'WorkersSize',
  }.freeze

  DEFAULT_ENABLED_METRICS = %i[enqueued retry_size].freeze

  def self.available_metrics
    METRIC_MAP.keys
  end

  def self.used_metrics
    @used_metrics ||= DEFAULT_ENABLED_METRICS
  end

  def self.use(*values)
    @used_metrics = values.flatten & available_metrics
  end

  def self.add_client_middleware
    Sidekiq.configure_client do |config|
      config.client_middleware do |chain|
        chain.add NewrelicSidekiqMetrics::Middleware
      end
    end
  end

  def self.add_server_middleware
    Sidekiq.configure_server do |config|
      config.client_middleware do |chain|
        chain.add NewrelicSidekiqMetrics::Middleware
      end
      config.server_middleware do |chain|
        chain.add NewrelicSidekiqMetrics::Middleware
      end
    end
  end
end

NewrelicSidekiqMetrics.add_client_middleware
NewrelicSidekiqMetrics.add_server_middleware

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
newrelic-sidekiq-metrics-0.2.0 lib/newrelic_sidekiq_metrics.rb