Class: PrometheusExporter::Server::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/prometheus_exporter/server/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Runner

Returns a new instance of Runner.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/prometheus_exporter/server/runner.rb', line 13

def initialize(options = {})
  @timeout = nil
  @port = nil
  @bind = nil
  @collector_class = nil
  @type_collectors = nil
  @prefix = nil
  @auth = nil
  @realm = nil
  @histogram = nil

  options.each { |k, v| send("#{k}=", v) if self.class.method_defined?("#{k}=") }
end

Instance Attribute Details

#authObject



80
81
82
# File 'lib/prometheus_exporter/server/runner.rb', line 80

def auth
  @auth || nil
end

#bindObject



96
97
98
# File 'lib/prometheus_exporter/server/runner.rb', line 96

def bind
  @bind || PrometheusExporter::DEFAULT_BIND_ADDRESS
end

#collector_classObject



100
101
102
# File 'lib/prometheus_exporter/server/runner.rb', line 100

def collector_class
  @collector_class || PrometheusExporter::Server::Collector
end

#histogramObject



129
130
131
# File 'lib/prometheus_exporter/server/runner.rb', line 129

def histogram
  @histogram || false
end

#labelObject



125
126
127
# File 'lib/prometheus_exporter/server/runner.rb', line 125

def label
  @label ||= PrometheusExporter::DEFAULT_LABEL
end

#portObject



92
93
94
# File 'lib/prometheus_exporter/server/runner.rb', line 92

def port
  @port || PrometheusExporter::DEFAULT_PORT
end

#prefixObject



88
89
90
# File 'lib/prometheus_exporter/server/runner.rb', line 88

def prefix
  @prefix || PrometheusExporter::DEFAULT_PREFIX
end

#realmObject



84
85
86
# File 'lib/prometheus_exporter/server/runner.rb', line 84

def realm
  @realm || PrometheusExporter::DEFAULT_REALM
end

#server_classObject



117
118
119
# File 'lib/prometheus_exporter/server/runner.rb', line 117

def server_class
  @server_class || PrometheusExporter::Server::WebServer
end

#timeoutObject



108
109
110
# File 'lib/prometheus_exporter/server/runner.rb', line 108

def timeout
  @timeout || PrometheusExporter::DEFAULT_TIMEOUT
end

#type_collectorsObject



104
105
106
# File 'lib/prometheus_exporter/server/runner.rb', line 104

def type_collectors
  @type_collectors || []
end

#unicorn_listen_addressObject

Returns the value of attribute unicorn_listen_address.



66
67
68
# File 'lib/prometheus_exporter/server/runner.rb', line 66

def unicorn_listen_address
  @unicorn_listen_address
end

#unicorn_pid_fileObject

Returns the value of attribute unicorn_pid_file.



66
67
68
# File 'lib/prometheus_exporter/server/runner.rb', line 66

def unicorn_pid_file
  @unicorn_pid_file
end

#verboseObject



112
113
114
115
# File 'lib/prometheus_exporter/server/runner.rb', line 112

def verbose
  return @verbose if defined?(@verbose)
  false
end

Instance Method Details

#collectorObject



121
122
123
# File 'lib/prometheus_exporter/server/runner.rb', line 121

def collector
  @_collector ||= collector_class.new
end

#startObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/prometheus_exporter/server/runner.rb', line 27

def start
  PrometheusExporter::Metric::Base.default_prefix = prefix
  PrometheusExporter::Metric::Base.default_labels = label

  if histogram
    PrometheusExporter::Metric::Base.default_aggregation = PrometheusExporter::Metric::Histogram
  end

  register_type_collectors

  unless collector.is_a?(PrometheusExporter::Server::CollectorBase)
    raise WrongInheritance,
          "Collector class must be inherited from PrometheusExporter::Server::CollectorBase"
  end

  if unicorn_listen_address && unicorn_pid_file
    require_relative "../instrumentation"

    local_client = PrometheusExporter::LocalClient.new(collector: collector)
    PrometheusExporter::Instrumentation::Unicorn.start(
      pid_file: unicorn_pid_file,
      listener_address: unicorn_listen_address,
      client: local_client,
    )
  end

  server =
    server_class.new(
      port: port,
      bind: bind,
      collector: collector,
      timeout: timeout,
      verbose: verbose,
      auth: auth,
      realm: realm,
    )
  server.start
end