Skip to content
This repository was archived by the owner on Dec 29, 2020. It is now read-only.

Free buffers #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ Require the library like you would expect:
Then create a new MemInfo object:

m = MemInfo.new
m.memtotal => 70000
m.memfree => 54300
m.memused => 15700
m.memtotal => 70000
m.memfree => 54300
m.memused => 15700
m.free_buffers => 75000

Take a look in lib/mem_info.rb for all fields that are available.

Expand Down
9 changes: 7 additions & 2 deletions lib/mem_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class MemInfo
@@attributes = {
:memtotal => "MemTotal",
:memfree => "MemFree",
:buffers => "Cached",
:buffers => "Buffers",
:cached => "Cached",
:swapcached => "SwapCached",
:active => "Active",
:inactive => "Inactive",
Expand Down Expand Up @@ -58,10 +59,14 @@ def initialize
def memused
@memtotal - @memfree
end

def free_buffers
@memfree + @buffers + @cached
end

private
def regex_match(attribute, line)
regex = Regexp.new("#{@@attributes[attribute]}:\\s*(.*?)\\s")
regex.match(line)[1] if regex === line
end
end
end