class ProcParser::MemInfo
Attributes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Contains the data in kilobytes
Public Class Methods
# 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
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
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
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
# 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