Class: MemInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/mem_info.rb

Defined Under Namespace

Classes: NoProcData

Constant Summary collapse

@@attributes =
{
  :memtotal       => "MemTotal",
  :memfree        => "MemFree",
  :buffers        => "Buffers",
  :cached         => "Cached",
  :swapcached     => "SwapCached",
  :active         => "Active",
  :inactive       => "Inactive",
  :active_anon    => "Active\(anon\)",
  :inactive_anon  => "Inactive\(anon\)",
  :active_file    => "Active\(file\)",
  :inactive_file  => "Inactive\(file\)",
  :unevictable    => "Unevictable",
  :mlocked        => "Mlocked",
  :swaptotal      => "SwapTotal",
  :swapfree       => "SwapFree",
  :dirty          => "Dirty",
  :writeback      => "Writeback",
  :anonpages      => "AnonPages",
  :mapped         => "Mapped",
  :slab           => "Slab",
  :sreclaimable   => "SReclaimable",
  :sunreclaim     => "SUnreclaim",
  :pagetables     => "PageTables",
  :nfs_unstable   => "NFS_Unstable",
  :bounce         => "Bounce",
  :writebacktmp   => "WritebackTmp",
  :commitlimit    => "CommitLimit",
  :committed_as   => "Committed_AS",
  :vmalloctotal   => "VmallocTotal",
  :vmallocused    => "VmallocUsed",
  :vmallocchunk   => "VmallocChunk",
  :directmap4k    => "DirectMap4k",
  :directmap2m    => "DirectMap2M"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemInfo

Returns a new instance of MemInfo.



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mem_info.rb', line 48

def initialize
  if File.exists?("/proc/meminfo")
    File.open("/proc/meminfo", "r") do |file|
      data = file.read
      @@attributes.keys.each do |attribute|
        instance_variable_set("@#{attribute.to_s}", regex_match(attribute, data).to_i)
      end
    end
  else
    raise NoProcData, "This system doesn't have /proc/meminfo data."
  end
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



4
5
6
# File 'lib/mem_info.rb', line 4

def active
  @active
end

#active_anonObject

Returns the value of attribute active_anon.



4
5
6
# File 'lib/mem_info.rb', line 4

def active_anon
  @active_anon
end

#active_fileObject

Returns the value of attribute active_file.



4
5
6
# File 'lib/mem_info.rb', line 4

def active_file
  @active_file
end

#anonpagesObject

Returns the value of attribute anonpages.



4
5
6
# File 'lib/mem_info.rb', line 4

def anonpages
  @anonpages
end

#bounceObject

Returns the value of attribute bounce.



4
5
6
# File 'lib/mem_info.rb', line 4

def bounce
  @bounce
end

#buffersObject

Returns the value of attribute buffers.



4
5
6
# File 'lib/mem_info.rb', line 4

def buffers
  @buffers
end

#cachedObject

Returns the value of attribute cached.



4
5
6
# File 'lib/mem_info.rb', line 4

def cached
  @cached
end

#commitlimitObject

Returns the value of attribute commitlimit.



4
5
6
# File 'lib/mem_info.rb', line 4

def commitlimit
  @commitlimit
end

#committed_asObject

Returns the value of attribute committed_as.



4
5
6
# File 'lib/mem_info.rb', line 4

def committed_as
  @committed_as
end

#directmap2mObject

Returns the value of attribute directmap2m.



4
5
6
# File 'lib/mem_info.rb', line 4

def directmap2m
  @directmap2m
end

#directmap4kObject

Returns the value of attribute directmap4k.



4
5
6
# File 'lib/mem_info.rb', line 4

def directmap4k
  @directmap4k
end

#dirtyObject

Returns the value of attribute dirty.



4
5
6
# File 'lib/mem_info.rb', line 4

def dirty
  @dirty
end

#inactiveObject

Returns the value of attribute inactive.



4
5
6
# File 'lib/mem_info.rb', line 4

def inactive
  @inactive
end

#inactive_anonObject

Returns the value of attribute inactive_anon.



4
5
6
# File 'lib/mem_info.rb', line 4

def inactive_anon
  @inactive_anon
end

#inactive_fileObject

Returns the value of attribute inactive_file.



4
5
6
# File 'lib/mem_info.rb', line 4

def inactive_file
  @inactive_file
end

#mappedObject

Returns the value of attribute mapped.



4
5
6
# File 'lib/mem_info.rb', line 4

def mapped
  @mapped
end

#memfreeObject

Returns the value of attribute memfree.



4
5
6
# File 'lib/mem_info.rb', line 4

def memfree
  @memfree
end

#memtotalObject

Returns the value of attribute memtotal.



4
5
6
# File 'lib/mem_info.rb', line 4

def memtotal
  @memtotal
end

#mlockedObject

Returns the value of attribute mlocked.



4
5
6
# File 'lib/mem_info.rb', line 4

def mlocked
  @mlocked
end

#nfs_unstableObject

Returns the value of attribute nfs_unstable.



4
5
6
# File 'lib/mem_info.rb', line 4

def nfs_unstable
  @nfs_unstable
end

#pagetablesObject

Returns the value of attribute pagetables.



4
5
6
# File 'lib/mem_info.rb', line 4

def pagetables
  @pagetables
end

#slabObject

Returns the value of attribute slab.



4
5
6
# File 'lib/mem_info.rb', line 4

def slab
  @slab
end

#sreclaimableObject

Returns the value of attribute sreclaimable.



4
5
6
# File 'lib/mem_info.rb', line 4

def sreclaimable
  @sreclaimable
end

#sunreclaimObject

Returns the value of attribute sunreclaim.



4
5
6
# File 'lib/mem_info.rb', line 4

def sunreclaim
  @sunreclaim
end

#swapcachedObject

Returns the value of attribute swapcached.



4
5
6
# File 'lib/mem_info.rb', line 4

def swapcached
  @swapcached
end

#swapfreeObject

Returns the value of attribute swapfree.



4
5
6
# File 'lib/mem_info.rb', line 4

def swapfree
  @swapfree
end

#swaptotalObject

Returns the value of attribute swaptotal.



4
5
6
# File 'lib/mem_info.rb', line 4

def swaptotal
  @swaptotal
end

#unevictableObject

Returns the value of attribute unevictable.



4
5
6
# File 'lib/mem_info.rb', line 4

def unevictable
  @unevictable
end

#vmallochunkObject

Returns the value of attribute vmallochunk.



4
5
6
# File 'lib/mem_info.rb', line 4

def vmallochunk
  @vmallochunk
end

#vmalloctotalObject

Returns the value of attribute vmalloctotal.



4
5
6
# File 'lib/mem_info.rb', line 4

def vmalloctotal
  @vmalloctotal
end

#vmallocusedObject

Returns the value of attribute vmallocused.



4
5
6
# File 'lib/mem_info.rb', line 4

def vmallocused
  @vmallocused
end

#writebackObject

Returns the value of attribute writeback.



4
5
6
# File 'lib/mem_info.rb', line 4

def writeback
  @writeback
end

#writebacktmpObject

Returns the value of attribute writebacktmp.



4
5
6
# File 'lib/mem_info.rb', line 4

def writebacktmp
  @writebacktmp
end

Instance Method Details

#free_buffersObject



65
66
67
# File 'lib/mem_info.rb', line 65

def free_buffers
  @memfree + @buffers + @cached
end

#memusedObject



61
62
63
# File 'lib/mem_info.rb', line 61

def memused
  @memtotal - @memfree
end