Class: ProcParser::MemInfo
- Inherits:
-
Object
- Object
- ProcParser::MemInfo
- Defined in:
- lib/proc_parser/mem_info.rb
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
-
#active ⇒ Object
Contains the data in kilobytes.
-
#active_anon ⇒ Object
Contains the data in kilobytes.
-
#active_file ⇒ Object
Contains the data in kilobytes.
-
#anonpages ⇒ Object
Contains the data in kilobytes.
-
#bounce ⇒ Object
Contains the data in kilobytes.
-
#buffers ⇒ Object
Contains the data in kilobytes.
-
#cached ⇒ Object
Contains the data in kilobytes.
-
#commitlimit ⇒ Object
Contains the data in kilobytes.
-
#committed_as ⇒ Object
Contains the data in kilobytes.
-
#directmap2m ⇒ Object
Contains the data in kilobytes.
-
#directmap4k ⇒ Object
Contains the data in kilobytes.
-
#dirty ⇒ Object
Contains the data in kilobytes.
-
#inactive ⇒ Object
Contains the data in kilobytes.
-
#inactive_anon ⇒ Object
Contains the data in kilobytes.
-
#inactive_file ⇒ Object
Contains the data in kilobytes.
-
#mapped ⇒ Object
Contains the data in kilobytes.
-
#memfree ⇒ Object
Contains the data in kilobytes.
-
#memtotal ⇒ Object
Contains the data in kilobytes.
-
#mlocked ⇒ Object
Contains the data in kilobytes.
-
#nfs_unstable ⇒ Object
Contains the data in kilobytes.
-
#pagetables ⇒ Object
Contains the data in kilobytes.
-
#slab ⇒ Object
Contains the data in kilobytes.
-
#sreclaimable ⇒ Object
Contains the data in kilobytes.
-
#sunreclaim ⇒ Object
Contains the data in kilobytes.
-
#swapcached ⇒ Object
Contains the data in kilobytes.
-
#swapfree ⇒ Object
Contains the data in kilobytes.
-
#swaptotal ⇒ Object
Contains the data in kilobytes.
-
#unevictable ⇒ Object
Contains the data in kilobytes.
-
#vmallochunk ⇒ Object
Contains the data in kilobytes.
-
#vmalloctotal ⇒ Object
Contains the data in kilobytes.
-
#vmallocused ⇒ Object
Contains the data in kilobytes.
-
#writeback ⇒ Object
Contains the data in kilobytes.
-
#writebacktmp ⇒ Object
Contains the data in kilobytes.
Instance Method Summary collapse
-
#free_buffers ⇒ Object
Memory available in the system.
-
#initialize(meminfo_file = '/proc/meminfo') ⇒ MemInfo
constructor
A new instance of MemInfo.
-
#memused ⇒ Object
Memory currently in use.
-
#swapused ⇒ Object
Swap currently in use.
Constructor Details
#initialize(meminfo_file = '/proc/meminfo') ⇒ MemInfo
Returns a new instance of MemInfo.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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 |
Instance Attribute Details
#active ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def active @active end |
#active_anon ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def active_anon @active_anon end |
#active_file ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def active_file @active_file end |
#anonpages ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def anonpages @anonpages end |
#bounce ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def bounce @bounce end |
#buffers ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def buffers @buffers end |
#cached ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def cached @cached end |
#commitlimit ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def commitlimit @commitlimit end |
#committed_as ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def committed_as @committed_as end |
#directmap2m ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def directmap2m @directmap2m end |
#directmap4k ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def directmap4k @directmap4k end |
#dirty ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def dirty @dirty end |
#inactive ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def inactive @inactive end |
#inactive_anon ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def inactive_anon @inactive_anon end |
#inactive_file ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def inactive_file @inactive_file end |
#mapped ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def mapped @mapped end |
#memfree ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def memfree @memfree end |
#memtotal ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def memtotal @memtotal end |
#mlocked ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def mlocked @mlocked end |
#nfs_unstable ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def nfs_unstable @nfs_unstable end |
#pagetables ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def pagetables @pagetables end |
#slab ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def slab @slab end |
#sreclaimable ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def sreclaimable @sreclaimable end |
#sunreclaim ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def sunreclaim @sunreclaim end |
#swapcached ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def swapcached @swapcached end |
#swapfree ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def swapfree @swapfree end |
#swaptotal ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def swaptotal @swaptotal end |
#unevictable ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def unevictable @unevictable end |
#vmallochunk ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def vmallochunk @vmallochunk end |
#vmalloctotal ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def vmalloctotal @vmalloctotal end |
#vmallocused ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def vmallocused @vmallocused end |
#writeback ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def writeback @writeback end |
#writebacktmp ⇒ Object
Contains the data in kilobytes
10 11 12 |
# File 'lib/proc_parser/mem_info.rb', line 10 def writebacktmp @writebacktmp end |
Instance Method Details
#free_buffers ⇒ Object
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
90 91 92 |
# File 'lib/proc_parser/mem_info.rb', line 90 def free_buffers @memfree + @buffers + @cached end |
#memused ⇒ Object
Memory currently in use.
We substract the free amount of memory to the total.
71 72 73 |
# File 'lib/proc_parser/mem_info.rb', line 71 def memused @memtotal - @memfree end |
#swapused ⇒ Object
Swap currently in use.
We substract the free amount of swap to the total.
78 79 80 |
# File 'lib/proc_parser/mem_info.rb', line 78 def swapused @swaptotal - @swapfree end |