class ProcParser::MemInfo

Attributes

active[RW]

Contains the data in kilobytes

active_anon[RW]

Contains the data in kilobytes

active_file[RW]

Contains the data in kilobytes

anonpages[RW]

Contains the data in kilobytes

bounce[RW]

Contains the data in kilobytes

buffers[RW]

Contains the data in kilobytes

cached[RW]

Contains the data in kilobytes

commitlimit[RW]

Contains the data in kilobytes

committed_as[RW]

Contains the data in kilobytes

directmap2m[RW]

Contains the data in kilobytes

directmap4k[RW]

Contains the data in kilobytes

dirty[RW]

Contains the data in kilobytes

inactive[RW]

Contains the data in kilobytes

inactive_anon[RW]

Contains the data in kilobytes

inactive_file[RW]

Contains the data in kilobytes

mapped[RW]

Contains the data in kilobytes

memfree[RW]

Contains the data in kilobytes

memtotal[RW]

Contains the data in kilobytes

mlocked[RW]

Contains the data in kilobytes

nfs_unstable[RW]

Contains the data in kilobytes

pagetables[RW]

Contains the data in kilobytes

slab[RW]

Contains the data in kilobytes

sreclaimable[RW]

Contains the data in kilobytes

sunreclaim[RW]

Contains the data in kilobytes

swapcached[RW]

Contains the data in kilobytes

swapfree[RW]

Contains the data in kilobytes

swaptotal[RW]

Contains the data in kilobytes

unevictable[RW]

Contains the data in kilobytes

vmallochunk[RW]

Contains the data in kilobytes

vmalloctotal[RW]

Contains the data in kilobytes

vmallocused[RW]

Contains the data in kilobytes

writeback[RW]

Contains the data in kilobytes

writebacktmp[RW]

Contains the data in kilobytes

Public Class Methods

new(meminfo_file = '/proc/meminfo') click to toggle source
# File lib/proc_parser/mem_info.rb, line 53
def initialize(meminfo_file = '/proc/meminfo')
  raise NoProcData, "This system doesn't have /proc/meminfo data." if !File.exist?(meminfo_file)

  File.open(meminfo_file, 'r') do |file|
    data = file.read
    @@attributes.each_key do |attribute|
      value, unit = regex_match(attribute, data)
      if unit != 'kB'
        raise NoProcData, 'Unsupported unit stored in meminfo.'
      end
      instance_variable_set("@#{attribute}", value.to_i)
    end
  end
end

Public Instance Methods

free_buffers() click to toggle source

Memory available in the system. It is not just the free memory.

The available memory is actually what the `free` command line tool calls `-/+ buffers/cache`. It uses information from /proc/meminfo: it sums the MemFree, the Buffers and the Cached.

cf. `free` source code: github.com/mmalecki/procps/blob/fe4c4a7314f32907b9f558ad0d8b8d0ff1cc76be/free.c#L97 cf. man 5 proc

# File lib/proc_parser/mem_info.rb, line 90
def free_buffers
  @memfree + @buffers + @cached
end
memused() click to toggle source

Memory currently in use.

We substract the free amount of memory to the total.

# File lib/proc_parser/mem_info.rb, line 71
def memused
  @memtotal - @memfree
end
swapused() click to toggle source

Swap currently in use.

We substract the free amount of swap to the total.

# File lib/proc_parser/mem_info.rb, line 78
def swapused
  @swaptotal - @swapfree
end

Private Instance Methods

regex_match(attribute, line) click to toggle source
# File lib/proc_parser/mem_info.rb, line 96
def regex_match(attribute, line)
  regex = Regexp.new("#{@@attributes[attribute]}:[[:space:]]*([[:digit:]]*) ([[:alpha:]]*)")
  m = regex.match(line)
  return m[1], m[2] if line =~ regex
end