Class: MoolMemory
- Inherits:
-
Object
- Object
- MoolMemory
- Defined in:
- lib/mool/memory.rb
Constant Summary collapse
- PATH_PROC_MEMORY =
"/proc/meminfo"
Instance Attribute Summary collapse
-
#mem_used ⇒ Object
Returns the value of attribute mem_used.
-
#unity ⇒ Object
Returns the value of attribute unity.
Instance Method Summary collapse
-
#initialize ⇒ MoolMemory
constructor
A new instance of MoolMemory.
- #to_b ⇒ Object
- #to_gb ⇒ Object
- #to_kb ⇒ Object
- #to_mb ⇒ Object
Constructor Details
#initialize ⇒ MoolMemory
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_used ⇒ Object
Returns the value of attribute mem_used.
4 5 6 |
# File 'lib/mool/memory.rb', line 4 def mem_used @mem_used end |
#unity ⇒ Object
Returns the value of attribute unity.
4 5 6 |
# File 'lib/mool/memory.rb', line 4 def unity @unity end |
Instance Method Details
#to_b ⇒ Object
16 |
# File 'lib/mool/memory.rb', line 16 def to_b; Mool.parse_to(self, (instance_variable_names - ["@unity"]), Mool::BYTES); end |
#to_gb ⇒ Object
19 |
# File 'lib/mool/memory.rb', line 19 def to_gb; Mool.parse_to(self, (instance_variable_names - ["@unity"]), Mool::GBYTES); end |
#to_kb ⇒ Object
17 |
# File 'lib/mool/memory.rb', line 17 def to_kb; Mool.parse_to(self, (instance_variable_names - ["@unity"]), Mool::KBYTES); end |
#to_mb ⇒ Object
18 |
# File 'lib/mool/memory.rb', line 18 def to_mb; Mool.parse_to(self, (instance_variable_names - ["@unity"]), Mool::MBYTES); end |