Class: GitLab::Exporter::CLI::Process

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

Overview

Process runner

Takes a pid and name for metrics

Constant Summary collapse

COMMAND_NAME =
"process".freeze

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Process

Returns a new instance of Process.



233
234
235
236
237
238
239
# File 'lib/gitlab_exporter/cli.rb', line 233

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

  @target = args.shift || $stdout
  @target = File.open(@target, "a") if @target.is_a?(String)
end

Instance Method Details

#helpObject



259
260
261
# File 'lib/gitlab_exporter/cli.rb', line 259

def help
  @options.help
end

#options(args) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/gitlab_exporter/cli.rb', line 241

def options(args)
  args.options do |opts|
    opts.banner = "Usage: #{EXECUTABLE_NAME} #{COMMAND_NAME} [options]"
    opts.on("--pid=123", "Process ID") do |val|
      @pid = val
    end
    opts.on("--pattern=worker", "Process command pattern") do |val|
      @pattern = val
    end
    opts.on("--name=NAME", "Process name to be used in metrics") do |val|
      @name = val
    end
    opts.on("--quantiles", "Return quantiles instead of exact metrics") do
      @quantiles = true
    end
  end
end

#runObject



263
264
265
266
267
268
269
# File 'lib/gitlab_exporter/cli.rb', line 263

def run
  ::GitLab::Exporter::ProcessProber.new(pid_or_pattern: @pid || @pattern, name: @name, quantiles: @quantiles)
                                   .probe_stat
                                   .probe_count
                                   .probe_smaps
                                   .write_to(@target)
end