Class: God::Conditions::MemoryUsage
- Inherits:
-
PollCondition
- Object
- Behavior
- God::Condition
- PollCondition
- God::Conditions::MemoryUsage
- Defined in:
- lib/god/conditions/memory_usage.rb
Instance Attribute Summary collapse
-
#above ⇒ Object
Returns the value of attribute above.
-
#times ⇒ Object
Returns the value of attribute times.
Attributes inherited from PollCondition
Attributes inherited from Behavior
Instance Method Summary collapse
-
#initialize ⇒ MemoryUsage
constructor
A new instance of MemoryUsage.
- #prepare ⇒ Object
- #test ⇒ Object
- #valid? ⇒ Boolean
Methods inherited from PollCondition
Methods inherited from God::Condition
Methods inherited from Behavior
#after_restart, #after_start, #after_stop, #before_restart, #before_start, #before_stop, generate
Constructor Details
#initialize ⇒ MemoryUsage
Returns a new instance of MemoryUsage.
7 8 9 10 11 |
# File 'lib/god/conditions/memory_usage.rb', line 7 def initialize super self.above = nil self.times = [1, 1] end |
Instance Attribute Details
#above ⇒ Object
Returns the value of attribute above.
5 6 7 |
# File 'lib/god/conditions/memory_usage.rb', line 5 def above @above end |
#times ⇒ Object
Returns the value of attribute times.
5 6 7 |
# File 'lib/god/conditions/memory_usage.rb', line 5 def times @times end |
Instance Method Details
#prepare ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/god/conditions/memory_usage.rb', line 13 def prepare if self.times.kind_of?(Integer) self.times = [self.times, self.times] end @timeline = Timeline.new(self.times[1]) end |
#test ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/god/conditions/memory_usage.rb', line 28 def test return false unless File.exist?(self.watch.pid_file) pid = File.read(self.watch.pid_file).strip process = System::Process.new(pid) @timeline.push(process.memory) if @timeline.select { |x| x > self.above }.size >= self.times.first @timeline.clear return true else return false end end |
#valid? ⇒ Boolean
21 22 23 24 25 26 |
# File 'lib/god/conditions/memory_usage.rb', line 21 def valid? valid = true valid &= complain("You must specify the 'pid_file' attribute on the Watch for :memory_usage") if self.watch.pid_file.nil? valid &= complain("You must specify the 'above' attribute for :memory_usage") if self.above.nil? valid end |