Method: CloudFlock::App::Watchdogs#utilized_memory

Defined in:
lib/cloudflock/app/common/watchdogs.rb

#utilized_memory(ssh, name) ⇒ Object

Public: Create a Watchdog which monitors the memory in use on a given host.

ssh - SSH session which the Watchdog should monitor. name - String describing the Watchdog.

Returns a Watchdog.



45
46
47
48
49
50
51
# File 'lib/cloudflock/app/common/watchdogs.rb', line 45

def utilized_memory(ssh, name)
  CloudFlock::Remote::SSH::Watchdog.new(name, ssh, 'free', 15) do |free|
    lines = free.lines.select { |line| /Swap/.match line }
    total,used = lines.empty? ? [0,0] : lines.map(&:to_f)[1..2]
    total > 0 ? free / total : 0.0
  end
end