added MemoryUsage and factored out ProcessCondition
[god.git] / lib / god / meddle.rb
blobcd88c75c451ed70f327635db4fdda944124d820c
1 module God
2   
3   class Meddle < Base
4     # config
5     attr_accessor :interval
6     
7     # api
8     attr_accessor :watches
9     
10     # Create a new instance that is ready for use by a configuration file
11     def initialize
12       self.watches = []
13     end
14       
15     # Instantiate a new, empty Watch object and pass it to the mandatory
16     # block. The attributes of the watch must be set by the configuration
17     # file.
18     def watch
19       w = Watch.new
20       yield(w)
21       @watches << w
22     end
23     
24     def monitor
25       threads = []
26       
27       @watches.each do |w|
28         threads << Thread.new do
29           while true do
30             w.run
31             sleep self.interval
32           end
33         end
34       end
35       
36       threads.each { |t| t.join }
37     end
38   end
39   
40 end