Class: DogNotGod::Commands::MemoryStats

Inherits:
ClientCommand show all
Defined in:
lib/client_commands.rb

Overview

Memory statistics, including swap

Instance Method Summary collapse

Methods inherited from ClientCommand

#get_hostname_from_shell, #run!

Instance Method Details

#_executeObject



106
107
108
# File 'lib/client_commands.rb', line 106

def _execute
  @resource["/mem_stats"].post({:hostname => @hostname, :mem_available => @memory_stats[:mem_available], :mem_used => @memory_stats[:mem_used], :swap_available => @memory_stats[:swap_available], :swap_used => @memory_stats[:swap_used]})
end

#_prepareObject



101
102
103
104
# File 'lib/client_commands.rb', line 101

def _prepare
  @hostname = get_hostname_from_shell
  @memory_stats = get_memory_and_swap_statistics_from_shell
end

#get_memory_and_swap_statistics_from_shellObject



110
111
112
113
114
115
116
# File 'lib/client_commands.rb', line 110

def get_memory_and_swap_statistics_from_shell
  # Note: the 'free' command is not available on Mac OSX
  mem = DogNotGod::Shell.call("free").split("\n")
  mem.shift # lose column headers
  
  {:mem_available => mem[0].split(" ")[3], :mem_used => mem[0].split(" ")[2], :swap_available => mem[2].split(" ")[3], :swap_used  => mem[2].split(" ")[2] }
end