Class: OsCtl::Cli::MemInfo
- Inherits:
-
Object
- Object
- OsCtl::Cli::MemInfo
- Defined in:
- lib/osctl/cli/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 |
# File 'lib/osctl/cli/meminfo.rb', line 3 def initialize(file = '/proc/meminfo') @content = File.read(file) end |
Instance Method Details
#buffers ⇒ Object
30 31 32 |
# File 'lib/osctl/cli/meminfo.rb', line 30 def buffers read_param('Buffers') end |
#cached ⇒ Object
15 16 17 |
# File 'lib/osctl/cli/meminfo.rb', line 15 def cached read_param('Cached') end |
#free(without_cache = true) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/osctl/cli/meminfo.rb', line 19 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)
51 52 53 54 55 56 57 58 |
# File 'lib/osctl/cli/meminfo.rb', line 51 def read_param(name) if @content =~ /^#{Regexp.escape(name)}:\s*(\d+)\s+kB$/ $1.to_i else nil end end |
#swap_cached ⇒ Object
42 43 44 |
# File 'lib/osctl/cli/meminfo.rb', line 42 def swap_cached read_param('SwapCached') end |
#swap_free ⇒ Object
46 47 48 |
# File 'lib/osctl/cli/meminfo.rb', line 46 def swap_free read_param('SwapFree') end |
#swap_total ⇒ Object
34 35 36 |
# File 'lib/osctl/cli/meminfo.rb', line 34 def swap_total read_param('SwapTotal') end |
#swap_used ⇒ Object
38 39 40 |
# File 'lib/osctl/cli/meminfo.rb', line 38 def swap_used swap_total - swap_free end |
#total ⇒ Object
7 8 9 |
# File 'lib/osctl/cli/meminfo.rb', line 7 def total read_param('MemTotal') end |
#used(without_cache = true) ⇒ Object
11 12 13 |
# File 'lib/osctl/cli/meminfo.rb', line 11 def used(without_cache = true) total - free(without_cache) end |