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



168
169
170
171
# File 'lib/gitlab_exporter/cli.rb', line 168

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

Instance Method Details

#helpObject



186
187
188
# File 'lib/gitlab_exporter/cli.rb', line 186

def help
  @options.help
end

#merged_configObject



190
191
192
193
194
195
# File 'lib/gitlab_exporter/cli.rb', line 190

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



173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/gitlab_exporter/cli.rb', line 173

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



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

def run
  validate!

  WebExporter.setup(merged_config)
  WebExporter.run!
end