Class: GitLab::Monitor::CLI::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_monitor/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.


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

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


233
234
235
# File 'lib/gitlab_monitor/cli.rb', line 233

def help
  @options.help
end

#options(args) ⇒ Object


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

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=unicorn", "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


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

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