public
Description: Ruby process monitor
Homepage: http://god.rubyforge.org
Clone URL: git://github.com/mojombo/god.git
Click here to lend your support to: god and make a donation at www.pledgie.com !
god / lib / god / system / process.rb
093f0737 » mojombo 2007-06-16 started implementation of S... 1 module God
2 module System
3
4 class Process
b1caa7a6 » eric 2009-10-25 Cache some frequent lookups... 5 def self.fetch_system_poller
6 @@poller ||= if SlashProcPoller.usable?
7 SlashProcPoller
8 else
9 PortablePoller
10 end
11 end
12
093f0737 » mojombo 2007-06-16 started implementation of S... 13 def initialize(pid)
14 @pid = pid.to_i
b1caa7a6 » eric 2009-10-25 Cache some frequent lookups... 15 @poller = self.class.fetch_system_poller.new(@pid)
093f0737 » mojombo 2007-06-16 started implementation of S... 16 end
17
18 # Return true if this process is running, false otherwise
19 def exists?
886f2815 » mojombo 2008-02-12 use Process.kill(0, ...) in... 20 !!::Process.kill(0, @pid) rescue false
093f0737 » mojombo 2007-06-16 started implementation of S... 21 end
22
23 # Memory usage in kilobytes (resident set size)
24 def memory
4bd50122 » kevinclark 2008-05-13 Fix args for pollers, initi... 25 @poller.memory
093f0737 » mojombo 2007-06-16 started implementation of S... 26 end
27
28 # Percentage memory usage
29 def percent_memory
4bd50122 » kevinclark 2008-05-13 Fix args for pollers, initi... 30 @poller.percent_memory
093f0737 » mojombo 2007-06-16 started implementation of S... 31 end
32
33 # Percentage CPU usage
34 def percent_cpu
4bd50122 » kevinclark 2008-05-13 Fix args for pollers, initi... 35 @poller.percent_cpu
093f0737 » mojombo 2007-06-16 started implementation of S... 36 end
37
38 private
39
466dbc34 » kevinclark 2008-05-13 Split System::Process into ... 40 def fetch_system_poller
b6f9cad5 » raggi 2008-06-16 * Fixed support for operat... 41 if SlashProcPoller.usable?
466dbc34 » kevinclark 2008-05-13 Split System::Process into ... 42 SlashProcPoller
43 else
44 PortablePoller
45 end
093f0737 » mojombo 2007-06-16 started implementation of S... 46 end
47 end
48
49 end
b1caa7a6 » eric 2009-10-25 Cache some frequent lookups... 50 end