Class: GitLab::Exporter::CLI::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_exporter/cli.rb

Overview

Run a web server that exposes the metrics specified in a config file

Constant Summary collapse

COMMAND_NAME =
"web".freeze

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Server

Returns a new instance of Server.



182
183
184
185
# File 'lib/gitlab_exporter/cli.rb', line 182

def initialize(args)
  @options = options(args)
  @options.parse!
end

Instance Method Details

#helpObject



200
201
202
# File 'lib/gitlab_exporter/cli.rb', line 200

def help
  @options.help
end

#merged_configObject



204
205
206
207
208
209
# File 'lib/gitlab_exporter/cli.rb', line 204

def merged_config
  config_from_file = Utils.deep_symbolize_hash_keys(YAML.safe_load_file(@config_file, aliases: true))
  config_from_command = extra_config_from_command

  config_from_file.deep_merge!(config_from_command)
end

#options(args) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/gitlab_exporter/cli.rb', line 187

def options(args)
  args.options do |opts|
    opts.banner = "Usage: #{EXECUTABLE_NAME} #{COMMAND_NAME} [options]"
    opts.on("-c config.yml", "Monitoring config") do |val|
      @config_file = val
    end
    opts.on("--extra-config-command command", "Shell command that returns YAML config to be merged
            with the config file") do |val|
      @extra_config_command = val
    end
  end
end

#runObject



211
212
213
214
215
216
# File 'lib/gitlab_exporter/cli.rb', line 211

def run
  validate!

  WebExporter.setup(merged_config)
  WebExporter.run!
end