diff options
author | Thom May <thom@may.lt> | 2015-09-02 10:36:46 +0100 |
---|---|---|
committer | Thom May <thom@may.lt> | 2015-09-02 10:36:46 +0100 |
commit | 0db3a820a2db3311d1e783643f53ad5e40ba9e6f (patch) | |
tree | 16885d96affa1ae68547f836adcb3fca2b498853 | |
parent | ffd9a0a0485718846381559946c8b38af7e46c70 (diff) | |
parent | 6fc98468afec0890a3a5595def6b09f1a06c3c78 (diff) | |
download | ohai-0db3a820a2db3311d1e783643f53ad5e40ba9e6f.tar.gz |
Merge pull request #609 from sh9189/linux_memory_changes
Make aix, solaris memory output consistent to linux, add spec test for linux memory
-rw-r--r-- | lib/ohai/plugins/aix/memory.rb | 8 | ||||
-rw-r--r-- | lib/ohai/plugins/solaris2/memory.rb | 6 | ||||
-rw-r--r-- | spec/unit/plugins/aix/memory_spec.rb | 8 | ||||
-rw-r--r-- | spec/unit/plugins/linux/memory_spec.rb | 204 | ||||
-rw-r--r-- | spec/unit/plugins/solaris2/memory_spec.rb | 6 |
5 files changed, 219 insertions, 13 deletions
diff --git a/lib/ohai/plugins/aix/memory.rb b/lib/ohai/plugins/aix/memory.rb index 9a8a26a7..c6729ea1 100644 --- a/lib/ohai/plugins/aix/memory.rb +++ b/lib/ohai/plugins/aix/memory.rb @@ -24,10 +24,12 @@ Ohai.plugin(:Memory) do memory[:swap] = Mash.new meminfo = shell_out("svmon -G -O unit=MB,summary=longreal | grep '[0-9]'").stdout - memory[:total], u, memory[:free] = meminfo.split + total_in_mb, u, free_in_mb = meminfo.split + memory[:total] = "#{total_in_mb.to_i * 1024}kB" + memory[:free] = "#{free_in_mb.to_i * 1024}kB" swapinfo = shell_out("swap -s").stdout.split #returns swap info in 4K blocks - memory[:swap]['total'] = (swapinfo[2].to_i / 1024.0) * 4 - memory[:swap]['free'] = (swapinfo[10].to_i / 1024.0) * 4 + memory[:swap]['total'] = "#{(swapinfo[2].to_i) * 4}kB" + memory[:swap]['free'] = "#{(swapinfo[10].to_i) * 4}kB" end end diff --git a/lib/ohai/plugins/solaris2/memory.rb b/lib/ohai/plugins/solaris2/memory.rb index 908a6380..c818698a 100644 --- a/lib/ohai/plugins/solaris2/memory.rb +++ b/lib/ohai/plugins/solaris2/memory.rb @@ -21,12 +21,12 @@ Ohai.plugin(:Memory) do memory Mash.new memory[:swap] = Mash.new meminfo = shell_out("prtconf | grep Memory").stdout - memory[:total] = meminfo.split[2].to_i + memory[:total] = "#{meminfo.split[2].to_i * 1024}kB" tokens = shell_out("swap -s").stdout.strip.split used_swap = tokens[8][0..-1].to_i #strip k from end free_swap = tokens[10][0..-1].to_i #strip k from end - memory[:swap][:total] = (used_swap + free_swap )/ 1024.0 #convert to MB - memory[:swap][:free] = free_swap / 1024.0 #convert to MB + memory[:swap][:total] = "#{used_swap + free_swap}kB" + memory[:swap][:free] = "#{free_swap}kB" end end diff --git a/spec/unit/plugins/aix/memory_spec.rb b/spec/unit/plugins/aix/memory_spec.rb index d4270127..4aa98626 100644 --- a/spec/unit/plugins/aix/memory_spec.rb +++ b/spec/unit/plugins/aix/memory_spec.rb @@ -27,21 +27,21 @@ describe Ohai::System, "AIX memory plugin" do it "should get total memory" do @plugin.run - expect(@plugin['memory']['total']).to eql("513280.00") + expect(@plugin['memory']['total']).to eql("#{513280 * 1024}kB") end it "should get free memory" do @plugin.run - expect(@plugin['memory']['free']).to eql("173245.83") + expect(@plugin['memory']['free']).to eql("#{173245.83.to_i * 1024}kB") end it "should get total swap" do @plugin.run - expect(@plugin['memory']['swap']['total']).to eql( (23887872 / 1024.0) * 4) + expect(@plugin['memory']['swap']['total']).to eql( "#{23887872 * 4}kB") end it "should get free swap" do @plugin.run - expect(@plugin['memory']['swap']['free']).to eql( (23598960 / 1024.0) * 4) + expect(@plugin['memory']['swap']['free']).to eql( "#{23598960 * 4}kB") end end diff --git a/spec/unit/plugins/linux/memory_spec.rb b/spec/unit/plugins/linux/memory_spec.rb new file mode 100644 index 00000000..cb2fe1b8 --- /dev/null +++ b/spec/unit/plugins/linux/memory_spec.rb @@ -0,0 +1,204 @@ +# +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') + +describe Ohai::System, "Linux memory plugin" do + before(:each) do + @plugin = get_plugin("linux/memory") + allow(@plugin).to receive(:collect_os).and_return(:linux) + @double_file = double("/proc/meminfo") + allow(@double_file).to receive(:each). + and_yield("MemTotal: 131932120 kB"). + and_yield("MemFree: 2269032 kB"). + and_yield("Buffers: 646368 kB"). + and_yield("Cached: 32346556 kB"). + and_yield("SwapCached: 312 kB"). + and_yield("Active: 98595796 kB"). + and_yield("Inactive: 18477320 kB"). + and_yield("HighTotal: 0 kB"). + and_yield("HighFree: 0 kB"). + and_yield("LowTotal: 131932120 kB"). + and_yield("LowFree: 2269032 kB"). + and_yield("SwapTotal: 16777208 kB"). + and_yield("SwapFree: 14127356 kB"). + and_yield("Dirty: 3212 kB"). + and_yield("Writeback: 0 kB"). + and_yield("AnonPages: 84082132 kB"). + and_yield("Mapped: 3445224 kB"). + and_yield("Slab: 9892096 kB"). + and_yield("SReclaimable: 362636 kB"). + and_yield("SUnreclaim: 18860 kB"). + and_yield("PageTables: 1759332 kB"). + and_yield("NFS_Unstable: 0 kB"). + and_yield("Bounce: 0 kB"). + and_yield("CommitLimit: 148709328 kB"). + and_yield("Committed_AS: 333717060 kB"). + 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("Hugepagesize: 2048 kB") + allow(File).to receive(:open).with("/proc/meminfo").and_return(@double_file) + end + + it "should get total memory" do + @plugin.run + expect(@plugin[:memory][:total]).to eql("131932120kB") + end + + it "should get free memory" do + @plugin.run + expect(@plugin[:memory][:free]).to eql("2269032kB") + end + + it "should get memory used for file buffers" do + @plugin.run + expect(@plugin[:memory][:buffers]).to eql("646368kB") + end + + it "should get cache memory" do + @plugin.run + expect(@plugin[:memory][:cached]).to eql("32346556kB") + end + + it "should get active memory" do + @plugin.run + expect(@plugin[:memory][:active]).to eql("98595796kB") + end + + it "should get inactive memory" do + @plugin.run + expect(@plugin[:memory][:inactive]).to eql("18477320kB") + end + + it "should get high_total memory" do + @plugin.run + expect(@plugin[:memory][:high_total]).to eql("0kB") + end + + it "should get high_free memory" do + @plugin.run + expect(@plugin[:memory][:high_free]).to eql("0kB") + end + + it "should get low_total memory" do + @plugin.run + expect(@plugin[:memory][:low_total]).to eql("131932120kB") + end + + it "should get low_free memory" do + @plugin.run + expect(@plugin[:memory][:low_free]).to eql("2269032kB") + end + + it "should get dirty memory" do + @plugin.run + expect(@plugin[:memory][:dirty]).to eql("3212kB") + end + + it "should get writeback memory" do + @plugin.run + expect(@plugin[:memory][:writeback]).to eql("0kB") + end + + it "should get anon_pages memory" do + @plugin.run + expect(@plugin[:memory][:anon_pages]).to eql("84082132kB") + end + + it "should get mapped memory" do + @plugin.run + expect(@plugin[:memory][:mapped]).to eql("3445224kB") + end + + + it "should get slab memory" do + @plugin.run + expect(@plugin[:memory][:slab]).to eql("9892096kB") + end + + it "should get slab_reclaimable memory" do + @plugin.run + expect(@plugin[:memory][:slab_reclaimable]).to eql("362636kB") + end + + it "should get slab_reclaimable memory" do + @plugin.run + expect(@plugin[:memory][:slab_unreclaim]).to eql("18860kB") + end + + it "should get page_tables memory" do + @plugin.run + expect(@plugin[:memory][:page_tables]).to eql("1759332kB") + end + + + it "should get nfs_unstable memory" do + @plugin.run + expect(@plugin[:memory][:nfs_unstable]).to eql("0kB") + end + + it "should get bounce memory" do + @plugin.run + expect(@plugin[:memory][:bounce]).to eql("0kB") + end + + it "should get commit_limit memory" do + @plugin.run + expect(@plugin[:memory][:commit_limit]).to eql("148709328kB") + end + + it "should get committed_as memory" do + @plugin.run + expect(@plugin[:memory][:committed_as]).to eql("333717060kB") + end + + it "should get vmalloc_total memory" do + @plugin.run + expect(@plugin[:memory][:vmalloc_total]).to eql("34359738367kB") + end + + it "should get vmalloc_used memory" do + @plugin.run + expect(@plugin[:memory][:vmalloc_used]).to eql("276796kB") + end + + it "should get vmalloc_chunk memory" do + @plugin.run + expect(@plugin[:memory][:vmalloc_chunk]).to eql("34359461515kB") + end + + it "should get total swap" do + @plugin.run + expect(@plugin[:memory][:swap][:total]).to eql("16777208kB") + end + + it "should get cached swap" do + @plugin.run + expect(@plugin[:memory][:swap][:cached]).to eql("312kB") + end + + it "should get free swap" do + @plugin.run + expect(@plugin[:memory][:swap][:free]).to eql("14127356kB") + end + + + +end diff --git a/spec/unit/plugins/solaris2/memory_spec.rb b/spec/unit/plugins/solaris2/memory_spec.rb index 6723768b..f2ef882b 100644 --- a/spec/unit/plugins/solaris2/memory_spec.rb +++ b/spec/unit/plugins/solaris2/memory_spec.rb @@ -27,17 +27,17 @@ describe Ohai::System, "Solaris2.X memory plugin" do it "should get the total memory" do @plugin.run - expect(@plugin['memory']['total']).to eql(8194) + expect(@plugin[:memory][:total]).to eql("#{8194 * 1024}kB") end it "should get total swap" do @plugin.run - expect(@plugin['memory']['swap']['total']).to eql((470096232 + 47057688) / 1024.0 ) + expect(@plugin[:memory][:swap][:total]).to eql("#{(470096232 + 47057688)}kB" ) end it "should get free swap" do @plugin.run - expect(@plugin['memory']['swap']['free']).to eql(47057688 / 1024.0 ) + expect(@plugin[:memory][:swap][:free]).to eql("47057688kB") end end |