Class: OsCtl::Lib::MemInfo
- Inherits:
-
Object
- Object
- OsCtl::Lib::MemInfo
- Defined in:
- lib/libosctl/meminfo.rb
Instance Method Summary collapse
- #buffers ⇒ Object
- #cached ⇒ Object
- #free(without_cache = true) ⇒ Object
-
#initialize(file = '/proc/meminfo') ⇒ MemInfo
constructor
A new instance of MemInfo.
- #read_param(name) ⇒ Object protected
- #swap_cached ⇒ Object
- #swap_free ⇒ Object
- #swap_total ⇒ Object
- #swap_used ⇒ Object
- #total ⇒ Object
- #used(without_cache = true) ⇒ Object
Constructor Details
#initialize(file = '/proc/meminfo') ⇒ MemInfo
Returns a new instance of MemInfo.
3 4 5 6 |
# File 'lib/libosctl/meminfo.rb', line 3 def initialize(file = '/proc/meminfo') @content = File.read(file) @values = {} end |
Instance Method Details
#buffers ⇒ Object
31 32 33 |
# File 'lib/libosctl/meminfo.rb', line 31 def buffers read_param('Buffers') end |
#cached ⇒ Object
16 17 18 |
# File 'lib/libosctl/meminfo.rb', line 16 def cached read_param('Cached') end |
#free(without_cache = true) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/libosctl/meminfo.rb', line 20 def free(without_cache = true) v = read_param('MemFree') if without_cache v + buffers + swap_cached else v end end |
#read_param(name) ⇒ Object (protected)
53 54 55 56 57 58 59 60 61 |
# File 'lib/libosctl/meminfo.rb', line 53 def read_param(name) if @values.has_key?(name) @values[name] elsif @content =~ /^#{Regexp.escape(name)}:\s*(\d+)\s+kB$/ @values[name] = ::Regexp.last_match(1).to_i end end |
#swap_cached ⇒ Object
43 44 45 |
# File 'lib/libosctl/meminfo.rb', line 43 def swap_cached read_param('SwapCached') end |
#swap_free ⇒ Object
47 48 49 |
# File 'lib/libosctl/meminfo.rb', line 47 def swap_free read_param('SwapFree') end |
#swap_total ⇒ Object
35 36 37 |
# File 'lib/libosctl/meminfo.rb', line 35 def swap_total read_param('SwapTotal') end |
#swap_used ⇒ Object
39 40 41 |
# File 'lib/libosctl/meminfo.rb', line 39 def swap_used swap_total - swap_free end |
#total ⇒ Object
8 9 10 |
# File 'lib/libosctl/meminfo.rb', line 8 def total read_param('MemTotal') end |
#used(without_cache = true) ⇒ Object
12 13 14 |
# File 'lib/libosctl/meminfo.rb', line 12 def used(without_cache = true) total - free(without_cache) end |