summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDzmitry Pasiukevich <dpasiukevich@gmail.com>2017-11-12 17:13:55 +0300
committerDzmitry Pasiukevich <dpasiukevich@gmail.com>2017-11-12 17:36:57 +0300
commitbde66b9fdc40c67f73c69e8086948c5a1a434436 (patch)
treeee173ff110495d2a3e521edd9390b7494699a535
parent0eeee400bf838357953ac342f66491cc67a6430e (diff)
downloadohai-bde66b9fdc40c67f73c69e8086948c5a1a434436.tar.gz
Add support for Linux MemAvailable
Signed-off-by: Dzmitry Pasiukevich <dpasiukevich@gmail.com>
-rw-r--r--lib/ohai/plugins/linux/memory.rb2
-rw-r--r--spec/unit/plugins/linux/memory_spec.rb6
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/ohai/plugins/linux/memory.rb b/lib/ohai/plugins/linux/memory.rb
index 144ad9d7..03d8057c 100644
--- a/lib/ohai/plugins/linux/memory.rb
+++ b/lib/ohai/plugins/linux/memory.rb
@@ -30,6 +30,8 @@ Ohai.plugin(:Memory) do
memory[:total] = "#{$1}#{$2}"
when /^MemFree:\s+(\d+) (.+)$/
memory[:free] = "#{$1}#{$2}"
+ when /^MemAvailable:\s+(\d+) (.+)$/
+ memory[:available] = "#{$1}#{$2}"
when /^Buffers:\s+(\d+) (.+)$/
memory[:buffers] = "#{$1}#{$2}"
when /^Cached:\s+(\d+) (.+)$/
diff --git a/spec/unit/plugins/linux/memory_spec.rb b/spec/unit/plugins/linux/memory_spec.rb
index e3a281ea..5859edd1 100644
--- a/spec/unit/plugins/linux/memory_spec.rb
+++ b/spec/unit/plugins/linux/memory_spec.rb
@@ -24,6 +24,7 @@ describe Ohai::System, "Linux memory plugin" do
allow(@double_file).to receive(:each).
and_yield("MemTotal: 131932120 kB").
and_yield("MemFree: 2269032 kB").
+ and_yield("MemAvailable: 9208922 kB").
and_yield("Buffers: 646368 kB").
and_yield("Cached: 32346556 kB").
and_yield("SwapCached: 312 kB").
@@ -68,6 +69,11 @@ describe Ohai::System, "Linux memory plugin" do
expect(@plugin[:memory][:free]).to eql("2269032kB")
end
+ it "should get available memory" do
+ @plugin.run
+ expect(@plugin[:memory][:available]).to eql("9208922kB")
+ end
+
it "should get memory used for file buffers" do
@plugin.run
expect(@plugin[:memory][:buffers]).to eql("646368kB")