Sha256: 5bd2699ad48c2f68d3a4fe0d05d64f4f014501958b20c898c3b05b964bdebec4

Contents?: true

Size: 1.31 KB

Versions: 10

Compression:

Stored size: 1.31 KB

Contents

module GovukPrometheusExporter
  def self.should_configure
    if File.basename($PROGRAM_NAME) == "rake" ||
        defined?(Rails) && (Rails.const_defined?("Console") || Rails.env == "test")
      false
    else
      ENV["GOVUK_PROMETHEUS_EXPORTER"] == "true"
    end
  end

  def self.configure
    return unless should_configure

    require "prometheus_exporter"
    require "prometheus_exporter/server"
    require "prometheus_exporter/middleware"

    if defined?(Sidekiq)
      Sidekiq.configure_server do |config|
        require "prometheus_exporter/instrumentation"
        config.server_middleware do |chain|
          chain.add PrometheusExporter::Instrumentation::Sidekiq
        end
        config.death_handlers << PrometheusExporter::Instrumentation::Sidekiq.death_handler
        config.on :startup do
          PrometheusExporter::Instrumentation::Process.start(type: "sidekiq")
          PrometheusExporter::Instrumentation::SidekiqProcess.start
          PrometheusExporter::Instrumentation::SidekiqQueue.start
          PrometheusExporter::Instrumentation::SidekiqStats.start
        end
      end
    end

    server = PrometheusExporter::Server::WebServer.new bind: "0.0.0.0", port: 9394
    server.start

    if defined?(Rails)
      Rails.application.middleware.unshift PrometheusExporter::Middleware
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
govuk_app_config-5.0.0 lib/govuk_app_config/govuk_prometheus_exporter.rb
govuk_app_config-4.13.0 lib/govuk_app_config/govuk_prometheus_exporter.rb
govuk_app_config-4.12.0 lib/govuk_app_config/govuk_prometheus_exporter.rb
govuk_app_config-4.11.1 lib/govuk_app_config/govuk_prometheus_exporter.rb
govuk_app_config-4.11.0 lib/govuk_app_config/govuk_prometheus_exporter.rb
govuk_app_config-4.10.1 lib/govuk_app_config/govuk_prometheus_exporter.rb
govuk_app_config-4.10.0 lib/govuk_app_config/govuk_prometheus_exporter.rb
govuk_app_config-4.9.0 lib/govuk_app_config/govuk_prometheus_exporter.rb
govuk_app_config-4.8.0 lib/govuk_app_config/govuk_prometheus_exporter.rb
govuk_app_config-4.7.1 lib/govuk_app_config/govuk_prometheus_exporter.rb