Module: Sidekiq::Prometheus::Exporter

Defined in:
lib/sidekiq/prometheus/exporter.rb,
lib/sidekiq/prometheus/exporter/cron.rb,
lib/sidekiq/prometheus/exporter/version.rb,
lib/sidekiq/prometheus/exporter/standard.rb,
lib/sidekiq/prometheus/exporter/exporters.rb,
lib/sidekiq/prometheus/exporter/scheduler.rb

Overview

Expose Prometheus metrics via Rack application or Sidekiq::Web application

Defined Under Namespace

Classes: Cron, Exporters, Scheduler, Standard

Constant Summary collapse

REQUEST_VERB =
'GET'.freeze
REQUEST_METHOD =
'REQUEST_METHOD'.freeze
NOT_FOUND_TEXT =
'Not Found'.freeze
MOUNT_PATH =
'/metrics'.freeze
HEADERS =
{
  Rack::CONTENT_TYPE => 'text/plain; version=0.0.4',
  Rack::CACHE_CONTROL => 'no-cache'
}.freeze
EXPORTERS =
Exporters.new
VERSION =

NOTE: Every version update dropds Docker patch version to 0

and every adjustment in Docker setup bumps it to +1
'0.2.1'.freeze
DOCKER_PATCH_VERSION =
'0'.freeze

Class Method Summary collapse

Class Method Details



21
22
23
24
25
26
27
28
# File 'lib/sidekiq/prometheus/exporter.rb', line 21

def banner
  exporters =
    EXPORTERS.enabled
      .map { |klass| "  - #{klass.name.split('::').last.downcase}" }
      .join("\n".freeze)

  "Enabled Sidekiq Prometheus exporters:\n#{exporters}"
end

.call(env) ⇒ Object



48
49
50
51
52
# File 'lib/sidekiq/prometheus/exporter.rb', line 48

def call(env)
  return [404, HEADERS, [NOT_FOUND_TEXT]] if env[REQUEST_METHOD] != REQUEST_VERB

  [200, HEADERS.dup, [EXPORTERS.to_s]]
end

.configure {|EXPORTERS| ... } ⇒ Object

Yields:



30
31
32
# File 'lib/sidekiq/prometheus/exporter.rb', line 30

def configure
  yield(EXPORTERS)
end

.registered(app) ⇒ Object



34
35
36
37
38
# File 'lib/sidekiq/prometheus/exporter.rb', line 34

def registered(app)
  app.get(MOUNT_PATH) do
    Sidekiq::Prometheus::Exporter.call(REQUEST_METHOD => REQUEST_VERB)
  end
end

.to_appObject



40
41
42
43
44
45
46
# File 'lib/sidekiq/prometheus/exporter.rb', line 40

def to_app
  Rack::Builder.app do
    map(MOUNT_PATH) do
      run Sidekiq::Prometheus::Exporter
    end
  end
end