diff options
author | Thom May <thom@may.lt> | 2015-08-14 15:03:25 +0100 |
---|---|---|
committer | Thom May <thom@may.lt> | 2015-08-14 15:03:25 +0100 |
commit | 3835cac6756082591c26692803b39540326e4cdc (patch) | |
tree | 76e28e661d74c8d79451e28d89a4a78254906c4c | |
parent | 5bb85a91476dc508b0c06f0bf1079e79279c8a81 (diff) | |
parent | 733781b6b91405a9e5820fe3ed2b05577bf62122 (diff) | |
download | ohai-3835cac6756082591c26692803b39540326e4cdc.tar.gz |
Merge pull request #599 from sh9189/solaris_swap_changes
Add swap space attributes for solaris memory plugin
-rw-r--r-- | lib/ohai/plugins/solaris2/memory.rb | 7 | ||||
-rw-r--r-- | spec/unit/plugins/solaris2/memory_spec.rb | 13 |
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/ohai/plugins/solaris2/memory.rb b/lib/ohai/plugins/solaris2/memory.rb index b493d73b..908a6380 100644 --- a/lib/ohai/plugins/solaris2/memory.rb +++ b/lib/ohai/plugins/solaris2/memory.rb @@ -19,7 +19,14 @@ Ohai.plugin(:Memory) do collect_data(:solaris2) do memory Mash.new + memory[:swap] = Mash.new meminfo = shell_out("prtconf | grep Memory").stdout memory[:total] = meminfo.split[2].to_i + + 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 end end diff --git a/spec/unit/plugins/solaris2/memory_spec.rb b/spec/unit/plugins/solaris2/memory_spec.rb index 73713695..6723768b 100644 --- a/spec/unit/plugins/solaris2/memory_spec.rb +++ b/spec/unit/plugins/solaris2/memory_spec.rb @@ -21,10 +21,23 @@ describe Ohai::System, "Solaris2.X memory plugin" do @plugin = get_plugin("solaris2/memory") allow(@plugin).to receive(:collect_os).and_return("solaris2") allow(@plugin).to receive(:shell_out).with("prtconf | grep Memory").and_return(mock_shell_out(0, "Memory size: 8194 Megabytes\n", "")) + @swap_s = "total: 112230656k bytes allocated + 357865576k reserved = 470096232k used, 47057688k available\n" + allow(@plugin).to receive(:shell_out).with("swap -s").and_return(mock_shell_out(0,@swap_s, "")) end it "should get the total memory" do @plugin.run expect(@plugin['memory']['total']).to eql(8194) end + + it "should get total swap" do + @plugin.run + expect(@plugin['memory']['swap']['total']).to eql((470096232 + 47057688) / 1024.0 ) + end + + it "should get free swap" do + @plugin.run + expect(@plugin['memory']['swap']['free']).to eql(47057688 / 1024.0 ) + end + end |