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.



206
207
208
209
210
211
212
# File 'lib/gitlab_exporter/cli.rb', line 206

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



232
233
234
# File 'lib/gitlab_exporter/cli.rb', line 232

def help
  @options.help
end

#options(args) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/gitlab_exporter/cli.rb', line 214

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



236
237
238
239
240
241
242
# File 'lib/gitlab_exporter/cli.rb', line 236

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