Class: Falcon::Supervisor::Statistics

Inherits:
Object
  • Object
show all
Defined in:
lib/falcon/supervisor.rb

Constant Summary collapse

PS =
"ps"
COLUMNS =

pid: Process Identifier pmem: Percentage Memory used. pcpu: Percentage Processor used. time: The process time used (executing on CPU). vsz: Virtual Size in kilobytes rss: Resident Set Size in kilobytes etime: The process elapsed time. command: The name of the process.

"pid,pmem,pcpu,time,vsz,rss,etime,command"

Instance Method Summary collapse

Constructor Details

#initialize(pgid: Process.ppid, ps: PS) ⇒ Statistics

Returns a new instance of Statistics.



35
36
37
38
# File 'lib/falcon/supervisor.rb', line 35

def initialize(pgid: Process.ppid, ps: PS)
  @ppid = pgid
  @ps = ps
end

Instance Method Details

#captureObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/falcon/supervisor.rb', line 50

def capture
  input, output = IO.pipe
  
  system(@ps, "--ppid", @ppid.to_s, "-o", COLUMNS, out: output, pgroup: true)
  output.close
  
  header, *lines = input.readlines.map(&:strip)
  
  keys = header.split(/\s+/).map(&:downcase)
  
  processes = lines.map do |line|
    keys.zip(line.split(/\s+/, keys.count)).to_h
  end
  
  return processes
end