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.



11
12
13
14
15
# File 'lib/prometheus_exporter/server/runner.rb', line 11

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

Instance Attribute Details

#unicorn_listen_addressObject

Returns the value of attribute unicorn_listen_address.



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

def unicorn_listen_address
  @unicorn_listen_address
end

#unicorn_pid_fileObject

Returns the value of attribute unicorn_pid_file.



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

def unicorn_pid_file
  @unicorn_pid_file
end

Instance Method Details

#collectorObject



98
99
100
# File 'lib/prometheus_exporter/server/runner.rb', line 98

def collector
  @_collector ||= collector_class.new
end

#collector_classObject



59
60
61
# File 'lib/prometheus_exporter/server/runner.rb', line 59

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

#collector_class=(collector_class) ⇒ Object



55
56
57
# File 'lib/prometheus_exporter/server/runner.rb', line 55

def collector_class=(collector_class)
  @collector_class = collector_class
end

#portObject



51
52
53
# File 'lib/prometheus_exporter/server/runner.rb', line 51

def port
  @port || PrometheusExporter::DEFAULT_PORT
end

#port=(port) ⇒ Object



47
48
49
# File 'lib/prometheus_exporter/server/runner.rb', line 47

def port=(port)
  @port = port
end

#prefixObject



43
44
45
# File 'lib/prometheus_exporter/server/runner.rb', line 43

def prefix
  @prefix || PrometheusExporter::DEFAULT_PREFIX
end

#prefix=(prefix) ⇒ Object



39
40
41
# File 'lib/prometheus_exporter/server/runner.rb', line 39

def prefix=(prefix)
  @prefix = prefix
end

#server_classObject



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

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

#server_class=(server_class) ⇒ Object



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

def server_class=(server_class)
  @server_class = server_class
end

#startObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/prometheus_exporter/server/runner.rb', line 17

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

  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
    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, collector: collector, timeout: timeout, verbose: verbose
  server.start
end

#timeoutObject



75
76
77
# File 'lib/prometheus_exporter/server/runner.rb', line 75

def timeout
  @timeout || PrometheusExporter::DEFAULT_TIMEOUT
end

#timeout=(timeout) ⇒ Object



71
72
73
# File 'lib/prometheus_exporter/server/runner.rb', line 71

def timeout=(timeout)
  @timeout = timeout
end

#type_collectorsObject



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

def type_collectors
  @type_collectors || []
end

#type_collectors=(type_collectors) ⇒ Object



63
64
65
# File 'lib/prometheus_exporter/server/runner.rb', line 63

def type_collectors=(type_collectors)
  @type_collectors = type_collectors
end

#verboseObject



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

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

#verbose=(verbose) ⇒ Object



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

def verbose=(verbose)
  @verbose = verbose
end