module Vidibus::Sysinfo::Memory

Returns used memory in megabytes.

Calls `free`

Public Class Methods

command() click to toggle source
# File lib/vidibus/sysinfo/memory.rb, line 24
def command
  'free -m'
end
parse(output) click to toggle source
# File lib/vidibus/sysinfo/memory.rb, line 28
def parse(output)
  new_format = !!output.match(/available/)
  if output.match(/^Mem:\s+([\d\s]+)$/)
    numbers = $1.split(/\s+/)
    total = numbers[0].to_i
    buffers = numbers[4].to_i
    cached = new_format ? buffers : numbers[5].to_i
    used = numbers[1].to_i
    unless new_format
      used -= buffers + cached
    end
    Result.new({
      total: total,
      used: used,
      free: total - used
    })
  end
end