Sha256: c24b9a20250287907e1a37838ff3a416c119aa8b899ecb0efa03483f547d88b9

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 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

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.14 docker/config.ru