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.



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

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.



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

def unicorn_listen_address
  @unicorn_listen_address
end

#unicorn_pid_fileObject

Returns the value of attribute unicorn_pid_file.



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

def unicorn_pid_file
  @unicorn_pid_file
end

Instance Method Details

#collectorObject



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

def collector
  @_collector ||= collector_class.new
end

#collector_classObject



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

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

#collector_class=(collector_class) ⇒ Object



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

def collector_class=(collector_class)
  @collector_class = collector_class
end

#portObject



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

def port
  @port || PrometheusExporter::DEFAULT_PORT
end

#port=(port) ⇒ Object



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

def port=(port)
  @port = port
end

#prefixObject



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

def prefix
  @prefix || PrometheusExporter::DEFAULT_PREFIX
end

#prefix=(prefix) ⇒ Object



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

def prefix=(prefix)
  @prefix = prefix
end

#server_classObject



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

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

#server_class=(server_class) ⇒ Object



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

def server_class=(server_class)
  @server_class = server_class
end

#startObject



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

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



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

def timeout
  @timeout || PrometheusExporter::DEFAULT_TIMEOUT
end

#timeout=(timeout) ⇒ Object



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

def timeout=(timeout)
  @timeout = timeout
end

#type_collectorsObject



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

def type_collectors
  @type_collectors || []
end

#type_collectors=(type_collectors) ⇒ Object



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

def type_collectors=(type_collectors)
  @type_collectors = type_collectors
end

#verboseObject



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

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

#verbose=(verbose) ⇒ Object



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

def verbose=(verbose)
  @verbose = verbose
end