diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2019-03-15 10:16:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-15 10:16:07 -0700 |
commit | b637569abe604ddf7c602384f6fb27cf5bd4678f (patch) | |
tree | a364209c1f023a97b876c186450a046ecc566101 | |
parent | 25857228433d879148ae39f293bbf2368e0b652e (diff) | |
parent | 34091e01d4aa533214fe60b137e2d520a4e23f34 (diff) | |
download | ohai-b637569abe604ddf7c602384f6fb27cf5bd4678f.tar.gz |
Merge pull request #1340 from davide125/memory
Parse new /proc/meminfo fields
-rw-r--r-- | lib/ohai/plugins/linux/memory.rb | 5 | ||||
-rw-r--r-- | spec/unit/plugins/linux/memory_spec.rb | 25 |
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..324364f4 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 |