Class: God::Conditions::MemoryUsage

Inherits:
PollCondition show all
Defined in:
lib/god/conditions/memory_usage.rb

Instance Attribute Summary collapse

Attributes inherited from PollCondition

#interval

Attributes inherited from Behavior

#watch

Instance Method Summary collapse

Methods inherited from PollCondition

#after, #before

Methods inherited from God::Condition

generate

Methods inherited from Behavior

#after_restart, #after_start, #after_stop, #before_restart, #before_start, #before_stop, generate

Constructor Details

#initializeMemoryUsage

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

#aboveObject

Returns the value of attribute above.



5
6
7
# File 'lib/god/conditions/memory_usage.rb', line 5

def above
  @above
end

#timesObject

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

#prepareObject



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

#testObject



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

Returns:

  • (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