diff options
author | Ben Kochie <bjk@soundcloud.com> | 2016-07-04 14:35:31 +0200 |
---|---|---|
committer | Ben Kochie <bjk@soundcloud.com> | 2016-07-04 19:27:27 +0200 |
commit | 4fe96f0256f95ff51f7d722f325343e61d584082 (patch) | |
tree | 627045890adc4b6d31fe9133a7077df972e79ead | |
parent | f9992941f3a39937362d1c98cb4dc63bd9d5b680 (diff) | |
download | ohai-4fe96f0256f95ff51f7d722f325343e61d584082.tar.gz |
Add support for Linux HugePages
Read the HugePages[0] information from `/proc/meminfo`.
[0]: https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
-rw-r--r-- | lib/ohai/plugins/linux/memory.rb | 11 | ||||
-rw-r--r-- | spec/unit/plugins/linux/memory_spec.rb | 31 |
2 files changed, 39 insertions, 3 deletions
diff --git a/lib/ohai/plugins/linux/memory.rb b/lib/ohai/plugins/linux/memory.rb index b663ed1e..144ad9d7 100644 --- a/lib/ohai/plugins/linux/memory.rb +++ b/lib/ohai/plugins/linux/memory.rb @@ -22,6 +22,7 @@ Ohai.plugin(:Memory) do collect_data(:linux) do memory Mash.new memory[:swap] = Mash.new + memory[:hugepages] = Mash.new File.open("/proc/meminfo").each do |line| case line @@ -81,6 +82,16 @@ Ohai.plugin(:Memory) do memory[:swap][:total] = "#{$1}#{$2}" when /^SwapFree:\s+(\d+) (.+)$/ memory[:swap][:free] = "#{$1}#{$2}" + when /^HugePages_Total:\s+(\d+)$/ + memory[:hugepages][:total] = "#{$1}" + when /^HugePages_Free:\s+(\d+)$/ + memory[:hugepages][:free] = "#{$1}" + when /^HugePages_Rsvd:\s+(\d+)$/ + memory[:hugepages][:reserved] = "#{$1}" + when /^HugePages_Surp:\s+(\d+)$/ + memory[:hugepages][:surplus] = "#{$1}" + when /^Hugepagesize:\s+(\d+) (.+)$/ + memory[:hugepage_size] = "#{$1}#{$2}" end end end diff --git a/spec/unit/plugins/linux/memory_spec.rb b/spec/unit/plugins/linux/memory_spec.rb index fd5bfc39..3a30ead3 100644 --- a/spec/unit/plugins/linux/memory_spec.rb +++ b/spec/unit/plugins/linux/memory_spec.rb @@ -50,9 +50,10 @@ describe Ohai::System, "Linux memory plugin" do and_yield("VmallocTotal: 34359738367 kB"). and_yield("VmallocUsed: 276796 kB"). and_yield("VmallocChunk: 34359461515 kB"). - and_yield("HugePages_Total: 0"). - and_yield("HugePages_Free: 0"). - and_yield("HugePages_Rsvd: 0"). + and_yield("HugePages_Total: 11542"). + and_yield("HugePages_Free: 11235"). + and_yield("HugePages_Rsvd: 11226"). + and_yield("HugePages_Surp: 0"). and_yield("Hugepagesize: 2048 kB") allow(File).to receive(:open).with("/proc/meminfo").and_return(@double_file) end @@ -197,4 +198,28 @@ describe Ohai::System, "Linux memory plugin" do expect(@plugin[:memory][:swap][:free]).to eql("14127356kB") end + it "should get total hugepages" do + @plugin.run + expect(@plugin[:memory][:hugepages][:total]).to eql("11542") + end + + it "should get free hugepages" do + @plugin.run + expect(@plugin[:memory][:hugepages][:free]).to eql("11235") + end + + it "should get reserved hugepages" do + @plugin.run + expect(@plugin[:memory][:hugepages][:reserved]).to eql("11226") + end + + it "should get surplus hugepages" do + @plugin.run + expect(@plugin[:memory][:hugepages][:surplus]).to eql("0") + end + + it "should get hugepage size" do + @plugin.run + expect(@plugin[:memory][:hugepage_size]).to eql("2048kB") + end end |