Class: Distem::Lib::MemoryTools

Inherits:
Object
  • Object
show all
Defined in:
lib/distem/distemlib/memorytools.rb

Overview

Class that allow to perform physical operations on a physical Memory resource

Class Method Summary (collapse)

Class Method Details

+ (Object) set_resource(pmem)

Set up a Resource::Memory resource to fit with the physical machine (node) properties

Attributes

  • pmem The Memory object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/distem/distemlib/memorytools.rb', line 11

def self.set_resource(pmem)
  str = File.read('/proc/meminfo')
  mem = {}
  str.each_line do |line|
    if line =~ /MemTotal\s*:\s*([0-9]+)\s*kB\s*/
      mem['capacity'] = Regexp.last_match(1).to_i / 1024
    elsif line =~ /SwapTotal\s*:\s*([0-9]+)\s*kB\s*/
      mem['swap'] = Regexp.last_match(1).to_i / 1024
    end
    if mem['capacity'] and mem['swap']
      pmem.capacity = mem['capacity']
      pmem.swap = mem['swap']
      break
    end
  end
end