Class: MoolMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/mool/memory.rb

Constant Summary collapse

PATH_PROC_MEMORY =
"/proc/meminfo"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMoolMemory

Returns a new instance of MoolMemory.



6
7
8
9
10
11
12
13
14
# File 'lib/mool/memory.rb', line 6

def initialize()
  File.read(PATH_PROC_MEMORY).scan(/(\S+):\s+(\d+)/).each do |meminfo|
    var = meminfo[0].gsub("(", "_").gsub(")", "").underscore
    instance_variable_set("@#{var}", (meminfo[1].to_f * Mool::PARSE_TYPES[Mool::KBYTES]).round(2))
    class_eval{attr_accessor var.to_sym}
  end
  @unity = Mool::BYTES
  @mem_used = @mem_total - (@mem_free + @cached + @buffers + @swap_cached )
end

Instance Attribute Details

#mem_usedObject

Returns the value of attribute mem_used.



4
5
6
# File 'lib/mool/memory.rb', line 4

def mem_used
  @mem_used
end

#unityObject

Returns the value of attribute unity.



4
5
6
# File 'lib/mool/memory.rb', line 4

def unity
  @unity
end

Instance Method Details

#to_bObject



16
# File 'lib/mool/memory.rb', line 16

def to_b;  Mool.parse_to(self, (instance_variable_names - ["@unity"]), Mool::BYTES); end

#to_gbObject



19
# File 'lib/mool/memory.rb', line 19

def to_gb; Mool.parse_to(self, (instance_variable_names - ["@unity"]), Mool::GBYTES); end

#to_kbObject



17
# File 'lib/mool/memory.rb', line 17

def to_kb; Mool.parse_to(self, (instance_variable_names - ["@unity"]), Mool::KBYTES); end

#to_mbObject



18
# File 'lib/mool/memory.rb', line 18

def to_mb; Mool.parse_to(self, (instance_variable_names - ["@unity"]), Mool::MBYTES); end