4 class MemoryUsage < PollCondition
5 attr_accessor :above, :times
14 if self.times.kind_of?(Integer)
15 self.times = [self.times, self.times]
18 @timeline = Timeline.new(self.times[1])
27 valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil?
28 valid &= complain("Attribute 'above' must be specified", self) if self.above.nil?
33 return false unless File.exist?(self.watch.pid_file)
35 pid = File.read(self.watch.pid_file).strip
36 process = System::Process.new(pid)
37 @timeline.push(process.memory)
39 history = "[" + @timeline.map { |x| "#{x > self.above ? '*' : ''}#{x}kb" }.join(", ") + "]"
41 if @timeline.select { |x| x > self.above }.size >= self.times.first
42 self.info = "memory out of bounds #{history}"
45 self.info = "memory within bounds #{history}"