Class: LinuxSystemMemory

Inherits:
SystemMemory show all
Defined in:
lib/memory.rb

Overview

Memory probe for Linux

Constant Summary

Constants inherited from SystemMemory

SystemMemory::UNLIMITED

Instance Attribute Summary

Attributes inherited from SystemMemory

#is_ecc, #size, #speed, #swap_size, #type

Instance Method Summary collapse

Methods inherited from SystemMemory

probe

Constructor Details

#initializeLinuxSystemMemory

Returns a new instance of LinuxSystemMemory.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/memory.rb', line 31

def initialize
  if `which lshw | wc -l | tr -d '[:space:]'` == '0'
    input = ask 'lshw is not installed, would you like to install it (y/n)?'
    if input == 'y'
      puts `sudo apt-get install -y lshw`
    else
      puts 'Cannot proceed without lshw executable, aborting.'
      exit 1
    end
  end

  cmd = "sudo lshw -c memory -short | grep 'System Memory' | " \
        "sed -e 's/.*memory *//' -e 's/GiB//' | awk '{print $1}'"
  @size = `#{cmd}`.to_i

  cmd = 'sudo lshw -c memory -short | grep MHz | '  \
        "sed -e 's/.*memory *//' -e 's/(//' | uniq | cut -f3,5 -d' '"
  @type, @speed, = `#{cmd}`.split ' ', 3
  @speed = @speed.to_i

  cmd = "grep SwapTotal /proc/meminfo | awk '{print $2}'"
  @swap_size = `#{cmd}`.to_i
  @swap_size /= 1_048_576

  cmd = "sudo dmidecode -t memory | grep '[Data|Total] Width' | " \
        "sort |  uniq | cut -d' ' -f 3 | uniq | wc -l"
  @is_ecc = `#{cmd}`.to_i != 1
end