class LinuxSystemMemory
Memory probe for Linux
Public Class Methods
new()
click to toggle source
# 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