Sha256: 0286352e1c597d1e7de81fd8d2f528184f7a951f3482d0374cf1ad076987d9e9
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
module God module Conditions class MemoryUsage < PollCondition attr_accessor :above, :times def initialize super self.above = nil self.times = [1, 1] end def prepare if self.times.kind_of?(Integer) self.times = [self.times, self.times] end @timeline = Timeline.new(self.times[1]) end def reset @timeline.clear end def valid? valid = true valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil? valid &= complain("Attribute 'above' must be specified", self) if self.above.nil? valid end 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) history = "[" + @timeline.map { |x| "#{x > self.above ? '*' : ''}#{x}kb" }.join(", ") + "]" if @timeline.select { |x| x > self.above }.size >= self.times.first self.info = "memory out of bounds #{history}" return true else self.info = "memory within bounds #{history}" return false end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
god-0.5.0 | lib/god/conditions/memory_usage.rb |