Class: GitLab::Monitor::WebExporter

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/gitlab_monitor/web_exporter.rb

Overview

Metrics web exporter

Defined Under Namespace

Classes: MemoryKillerMiddleware

Class Method Summary collapse

Class Method Details

.setup(config) ⇒ Object


39
40
41
42
43
44
45
# File 'lib/gitlab_monitor/web_exporter.rb', line 39

def setup(config)
  setup_server(config[:server])
  setup_probes(config[:probes])

  memory_threshold = (config[:server] && config[:server][:memory_threshold]) || 1024
  use MemoryKillerMiddleware, memory_threshold
end

.setup_probes(config) ⇒ Object


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/gitlab_monitor/web_exporter.rb', line 54

def setup_probes(config)
  (config || {}).each do |probe_name, params|
    opts =
      if params.delete(:multiple)
        params
      else
        { probe_name => params }
      end

    get "/#{probe_name}" do
      content_type "text/plain; version=0.0.4"
      prober = Prober.new(opts, metrics: PrometheusMetrics.new(include_timestamp: false))

      prober.probe_all
      prober.write_to(response)

      response
    end
  end
end

.setup_server(config) ⇒ Object


47
48
49
50
51
52
# File 'lib/gitlab_monitor/web_exporter.rb', line 47

def setup_server(config)
  config ||= {}

  set(:bind, config.fetch(:listen_address, "0.0.0.0"))
  set(:port, config.fetch(:listen_port, 9168))
end