summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Cavalca <dcavalca@fb.com>2019-02-25 13:50:19 -0500
committerDavide Cavalca <dcavalca@fb.com>2019-02-25 14:42:12 -0500
commit9bb708b72b68ad836b7f324b770eac4b421b019a (patch)
tree646b96d0a3b24864c3bdafb935236dd51a7c1f54
parent25857228433d879148ae39f293bbf2368e0b652e (diff)
downloadohai-9bb708b72b68ad836b7f324b770eac4b421b019a.tar.gz
Parse new /proc/meminfo fields
Signed-off-by: Davide Cavalca <dcavalca@fb.com>
-rw-r--r--lib/ohai/plugins/linux/memory.rb5
-rw-r--r--spec/unit/plugins/linux/memory_spec.rb25
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/ohai/plugins/linux/memory.rb b/lib/ohai/plugins/linux/memory.rb
index e878df0b..a459611e 100644
--- a/lib/ohai/plugins/linux/memory.rb
+++ b/lib/ohai/plugins/linux/memory.rb
@@ -23,6 +23,7 @@ Ohai.plugin(:Memory) do
memory Mash.new
memory[:swap] = Mash.new
memory[:hugepages] = Mash.new
+ memory[:directmap] = Mash.new
File.open("/proc/meminfo").each do |line|
case line
@@ -94,6 +95,10 @@ Ohai.plugin(:Memory) do
memory[:hugepages][:surplus] = $1.to_s
when /^Hugepagesize:\s+(\d+) (.+)$/
memory[:hugepage_size] = "#{$1}#{$2}"
+ when /^Hugetlb:\s+(\d+) (.+)$/
+ memory[:hugetlb] = "#{$1}#{$2}"
+ when /^DirectMap([0-9][a-zA-Z]):\s+(\d+) (.+)$/
+ memory[:directmap][$1.to_sym] = "#{$2}#{$3}"
end
end
end
diff --git a/spec/unit/plugins/linux/memory_spec.rb b/spec/unit/plugins/linux/memory_spec.rb
index d0d0e2a9..b2bda21f 100644
--- a/spec/unit/plugins/linux/memory_spec.rb
+++ b/spec/unit/plugins/linux/memory_spec.rb
@@ -56,6 +56,11 @@ describe Ohai::System, "Linux memory plugin" do
.and_yield("HugePages_Rsvd: 11226")
.and_yield("HugePages_Surp: 0")
.and_yield("Hugepagesize: 2048 kB")
+ .and_yield("Hugetlb: 0 kB")
+ .and_yield("DirectMap4k: 3720736 kB")
+ .and_yield("DirectMap2M: 12795904 kB")
+ .and_yield("DirectMap1G: 0 kB")
+
allow(File).to receive(:open).with("/proc/meminfo").and_return(@double_file)
end
@@ -228,4 +233,24 @@ describe Ohai::System, "Linux memory plugin" do
@plugin.run
expect(@plugin[:memory][:hugepage_size]).to eql("2048kB")
end
+
+ it "should get hugetlb memory" do
+ @plugin.run
+ expect(@plugin[:memory][:hugetlb]).to eql("0kB")
+ end
+
+ it "should get directmap 4k memory" do
+ @plugin.run
+ expect(@plugin[:memory][:directmap][:'4k']).to eql("3720736kB")
+ end
+
+ it "should get directmap 2M memory" do
+ @plugin.run
+ expect(@plugin[:memory][:directmap][:'2M']).to eql("12795904kB")
+ end
+
+ it "should get directmap 1G memory" do
+ @plugin.run
+ expect(@plugin[:memory][:directmap][:'1G']).to eql("0kB")
+ end
end