Class: Cumuli::PS
- Inherits:
-
Object
- Object
- Cumuli::PS
- Defined in:
- lib/cumuli/ps.rb
Defined Under Namespace
Classes: Line
Constant Summary collapse
- REGEX =
/ruby|resque|foreman|rvm|node/
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
Class Method Summary collapse
Instance Method Summary collapse
- #children(pid = root_pid) ⇒ Object
- #family(pid = root_pid) ⇒ Object
- #foremans ⇒ Object
-
#initialize(list = self.class.list) ⇒ PS
constructor
A new instance of PS.
- #int(pids = [root_pids]) ⇒ Object
- #kill(pids = [root_pid]) ⇒ Object
- #line(pid = root_pid) ⇒ Object
- #ppid_hash ⇒ Object
- #report(pid = root_pid) ⇒ Object
- #report_all ⇒ Object
- #root ⇒ Object
- #root_pid ⇒ Object
Constructor Details
Instance Attribute Details
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
5 6 7 |
# File 'lib/cumuli/ps.rb', line 5 def lines @lines end |
Class Method Details
.list ⇒ Object
102 103 104 |
# File 'lib/cumuli/ps.rb', line 102 def self.list `ps axo pid,ppid,comm,args,user` end |
Instance Method Details
#children(pid = root_pid) ⇒ Object
81 82 83 |
# File 'lib/cumuli/ps.rb', line 81 def children(pid=root_pid) ppid_hash[pid] end |
#family(pid = root_pid) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/cumuli/ps.rb', line 70 def family(pid=root_pid) collection = [] if kids = children(pid) collection += kids kids.each do |k| collection += family(k) end end collection end |
#foremans ⇒ Object
40 41 42 |
# File 'lib/cumuli/ps.rb', line 40 def foremans lines.select{|l| l.command.match(/foreman: master/) }.sort end |
#int(pids = [root_pids]) ⇒ Object
44 45 46 47 48 |
# File 'lib/cumuli/ps.rb', line 44 def int(pids=[root_pids]) pids.compact.each do |pid| Process.kill('INT', pid) end end |
#kill(pids = [root_pid]) ⇒ Object
50 51 52 53 54 |
# File 'lib/cumuli/ps.rb', line 50 def kill(pids=[root_pid]) pids.compact.each do |pid| Process.kill(9, pid) end end |
#line(pid = root_pid) ⇒ Object
65 66 67 68 |
# File 'lib/cumuli/ps.rb', line 65 def line(pid=root_pid) line = lines.detect{|l| l.pid == pid } line && line.to_s end |
#ppid_hash ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/cumuli/ps.rb', line 56 def ppid_hash lines .inject({}) do |hash, line| hash[line.ppid] ||= [] hash[line.ppid] << line.pid hash end end |
#report(pid = root_pid) ⇒ Object
85 86 87 88 89 90 91 92 |
# File 'lib/cumuli/ps.rb', line 85 def report(pid=root_pid) r = [line(pid).to_s] family(pid).each do |p| l = line(p) r << l.to_s end r.join("\n") end |
#report_all ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/cumuli/ps.rb', line 94 def report_all r = [] foremans.each do |line| r << report(line.pid) end r.join("\n") end |
#root ⇒ Object
36 37 38 |
# File 'lib/cumuli/ps.rb', line 36 def root foremans.first end |