Sha256: c5c5b8ccff1e98e06d7edd96dd6f9a7a8c63aed08fb9c72c51ca5b57cc7c03f8

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'sidekiq'
require 'sidekiq/prometheus/exporter'

config = {}
config[:url] = ENV['REDIS_URL'] if ENV.key?('REDIS_URL')

unless config.key?(:url)
  host = ENV.fetch('REDIS_HOST', 'localhost')
  port = ENV.fetch('REDIS_PORT', 6379)
  db_number = ENV.fetch('REDIS_DB_NUMBER', 0)
  password = ":#{ENV['REDIS_PASSWORD']}" if ENV.key?('REDIS_PASSWORD')

  config[:url] = "redis://#{password}@#{host}:#{port}/#{db_number}"
end

if ENV.key?('REDIS_NAMESPACE')
  require 'redis-namespace'

  config[:namespace] = ENV['REDIS_NAMESPACE']
end

if ENV.key?('REDIS_SENTINELS')
  require 'uri'

  config[:role] = ENV.fetch('REDIS_SENTINEL_ROLE', :master).to_sym
  config[:sentinels] = ENV['REDIS_SENTINELS'].split(',').map do |url|
    uri = URI.parse(url.strip)
    cfg = {host: uri.host || 'localhost', port: uri.port || 26379} # rubocop:disable Style/NumericLiterals
    cfg[:password] = ":#{uri.password}" if uri.password
    cfg
  end
end

config[:id] = nil if ENV.key?('REDIS_DISABLE_CLIENT_ID')

Sidekiq.configure_client { |client| client.redis = config }

run Sidekiq::Prometheus::Exporter.to_app

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-prometheus-exporter-0.1.15 docker/config.ru