Module: Sidekiq::Queues::Exporter

Defined in:
lib/sidekiq/queues/exporter.rb,
lib/sidekiq/queues/exporter/version.rb

Constant Summary collapse

REQUEST_VERB =
'GET'.freeze
REQUEST_METHOD =
'REQUEST_METHOD'.freeze
MOUNT_PATH =
'/metrics'.freeze
HEADERS =
{'Content-Type' => 'text/plain; version=0.1.0', 'Cache-Control' => 'no-cache'}.freeze
VERSION =
'0.1.2'

Class Method Summary collapse

Class Method Details

.call(env) ⇒ Object



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

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

  [200, HEADERS, [exports]]
end

.exportsObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/sidekiq/queues/exporter.rb', line 16

def exports
  @queues = Sidekiq::Queue.all.map do |queue|
    {
      queue_name: queue.name,
      queue_size: queue.size
    }
  end
  template = ERB.new(File.read(File.expand_path('templates/queues.erb', __dir__)))
  template.result(binding).chomp!
end

.registered(app) ⇒ Object



27
28
29
30
31
# File 'lib/sidekiq/queues/exporter.rb', line 27

def registered(app)
  app.get(MOUNT_PATH) do
    call(REQUEST_METHOD => REQUEST_VERB)
  end
end

.to_appObject



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

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