Class: Informo::Memory

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

Overview

This class is used to return various physical memory related information. For example: how many modules are installed, module size, etc

For virtualized systems some of these might not be applicable

Instance Method Summary collapse

Instance Method Details

#installedObject

returns the amount of physical memory installed



40
41
42
43
44
45
46
47
# File 'lib/informo/memory.rb', line 40

def installed
  `free -m`.each_line do |line|
    if line =~ /^Mem.+?(\d+)\s+/
      installed_memory = $1
      return installed_memory
    end
  end
end

#max_capacityObject

returns the maximum amount of memory supported by the bios/system



30
31
32
33
34
35
36
37
# File 'lib/informo/memory.rb', line 30

def max_capacity
  `dmidecode -t 5`.each_line do |line|
    if line =~ /Maximum Total Memory Size.+?(\d+)\s+/
      max_capacity = $1
      return max_capacity
    end
  end
end

#max_module_sizeObject

returns the maximum size for memory modules



10
11
12
13
14
15
16
17
# File 'lib/informo/memory.rb', line 10

def max_module_size
  `dmidecode -t 5`.each_line do |line|
    if line =~ /Maximum Memory Module Size.+?(\d+)\s+/
      max_module_size = $1
      return max_module_size
    end
  end
end

#max_modulesObject

returns the maximum amount of memory slots.



20
21
22
23
24
25
26
27
# File 'lib/informo/memory.rb', line 20

def max_modules
  `dmidecode -t 5`.each_line do |line|
    if line =~ /Associated Memory Slots.+?(\d+)\s+/
      max_modules = $1
      return max_modules
    end
  end
end

#slotsObject

returns details for memory installed in each memory slot

  • size

  • location on board

  • speed

  • form factor



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/informo/memory.rb', line 56

def slots
  count = -1
  modules = Array.new
  
  `dmidecode -t 17`.each_line do |line|
    if line =~ /\ccI(Array Handle|Size|Locator|Speed|Form Factor):\s*(.*)$/
      key, value = $1, $2
      if key =~ /Array Handle/
        count += 1
        modules[count] = Hash.new
      else
        key = "type" if key =~ /Form Factor/
        modules[count][key.downcase] = value
      end
    end
  end
  
  return modules
end