summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShahul Hameed <sh9189@gmail.com>2015-08-19 10:44:29 -0400
committerShahul Hameed <sh9189@gmail.com>2015-08-19 10:44:29 -0400
commitce32621b7f1b20787517570adc25b81127bcfdfa (patch)
treef79d1c604d823cb029f8cc668f1be6ead86457b3
parentc74fd8ab8748cfd718ff404c4485f1f8144474e8 (diff)
downloadohai-ce32621b7f1b20787517570adc25b81127bcfdfa.tar.gz
Add spec test for linux memory plugin
-rw-r--r--lib/ohai/plugins/linux/memory.rb58
-rw-r--r--spec/unit/plugins/linux/memory_spec.rb56
2 files changed, 57 insertions, 57 deletions
diff --git a/lib/ohai/plugins/linux/memory.rb b/lib/ohai/plugins/linux/memory.rb
index 728a38cf..ad039409 100644
--- a/lib/ohai/plugins/linux/memory.rb
+++ b/lib/ohai/plugins/linux/memory.rb
@@ -26,62 +26,62 @@ Ohai.plugin(:Memory) do
File.open("/proc/meminfo").each do |line|
case line
when /^MemTotal:\s+(\d+) (.+)$/
- memory[:total] = $1.to_i / 1024.0
+ memory[:total] = "#{$1}#{$2}"
when /^MemFree:\s+(\d+) (.+)$/
- memory[:free] = $1.to_i / 1024.0
+ memory[:free] = "#{$1}#{$2}"
when /^Buffers:\s+(\d+) (.+)$/
- memory[:buffers] = $1.to_i / 1024.0
+ memory[:buffers] = "#{$1}#{$2}"
when /^Cached:\s+(\d+) (.+)$/
- memory[:cached] = $1.to_i / 1024.0
+ memory[:cached] = "#{$1}#{$2}"
when /^Active:\s+(\d+) (.+)$/
- memory[:active] = $1.to_i / 1024.0
+ memory[:active] = "#{$1}#{$2}"
when /^Inactive:\s+(\d+) (.+)$/
- memory[:inactive] = $1.to_i / 1024.0
+ memory[:inactive] = "#{$1}#{$2}"
when /^HighTotal:\s+(\d+) (.+)$/
- memory[:high_total] = $1.to_i / 1024.0
+ memory[:high_total] = "#{$1}#{$2}"
when /^HighFree:\s+(\d+) (.+)$/
- memory[:high_free] = $1.to_i / 1024.0
+ memory[:high_free] = "#{$1}#{$2}"
when /^LowTotal:\s+(\d+) (.+)$/
- memory[:low_total] = $1.to_i / 1024.0
+ memory[:low_total] = "#{$1}#{$2}"
when /^LowFree:\s+(\d+) (.+)$/
- memory[:low_free] = $1.to_i / 1024.0
+ memory[:low_free] = "#{$1}#{$2}"
when /^Dirty:\s+(\d+) (.+)$/
- memory[:dirty] = $1.to_i / 1024.0
+ memory[:dirty] = "#{$1}#{$2}"
when /^Writeback:\s+(\d+) (.+)$/
- memory[:writeback] = $1.to_i / 1024.0
+ memory[:writeback] = "#{$1}#{$2}"
when /^AnonPages:\s+(\d+) (.+)$/
- memory[:anon_pages] = $1.to_i / 1024.0
+ memory[:anon_pages] = "#{$1}#{$2}"
when /^Mapped:\s+(\d+) (.+)$/
- memory[:mapped] = $1.to_i / 1024.0
+ memory[:mapped] = "#{$1}#{$2}"
when /^Slab:\s+(\d+) (.+)$/
- memory[:slab] = $1.to_i / 1024.0
+ memory[:slab] = "#{$1}#{$2}"
when /^SReclaimable:\s+(\d+) (.+)$/
- memory[:slab_reclaimable] = $1.to_i / 1024.0
+ memory[:slab_reclaimable] = "#{$1}#{$2}"
when /^SUnreclaim:\s+(\d+) (.+)$/
- memory[:slab_unreclaim] = $1.to_i / 1024.0
+ memory[:slab_unreclaim] = "#{$1}#{$2}"
when /^PageTables:\s+(\d+) (.+)$/
- memory[:page_tables] = $1.to_i / 1024.0
+ memory[:page_tables] = "#{$1}#{$2}"
when /^NFS_Unstable:\s+(\d+) (.+)$/
- memory[:nfs_unstable] = $1.to_i / 1024.0
+ memory[:nfs_unstable] = "#{$1}#{$2}"
when /^Bounce:\s+(\d+) (.+)$/
- memory[:bounce] = $1.to_i / 1024.0
+ memory[:bounce] = "#{$1}#{$2}"
when /^CommitLimit:\s+(\d+) (.+)$/
- memory[:commit_limit] = $1.to_i / 1024.0
+ memory[:commit_limit] = "#{$1}#{$2}"
when /^Committed_AS:\s+(\d+) (.+)$/
- memory[:committed_as] = $1.to_i / 1024.0
+ memory[:committed_as] = "#{$1}#{$2}"
when /^VmallocTotal:\s+(\d+) (.+)$/
- memory[:vmalloc_total] = $1.to_i / 1024.0
+ memory[:vmalloc_total] = "#{$1}#{$2}"
when /^VmallocUsed:\s+(\d+) (.+)$/
- memory[:vmalloc_used] = $1.to_i / 1024.0
+ memory[:vmalloc_used] = "#{$1}#{$2}"
when /^VmallocChunk:\s+(\d+) (.+)$/
- memory[:vmalloc_chunk] = $1.to_i / 1024.0
+ memory[:vmalloc_chunk] = "#{$1}#{$2}"
when /^SwapCached:\s+(\d+) (.+)$/
- memory[:swap][:cached] = $1.to_i / 1024.0
+ memory[:swap][:cached] = "#{$1}#{$2}"
when /^SwapTotal:\s+(\d+) (.+)$/
- memory[:swap][:total] = $1.to_i / 1024.0
+ memory[:swap][:total] = "#{$1}#{$2}"
when /^SwapFree:\s+(\d+) (.+)$/
- memory[:swap][:free] = $1.to_i / 1024.0
+ memory[:swap][:free] = "#{$1}#{$2}"
end
end
end
-end
+end \ No newline at end of file
diff --git a/spec/unit/plugins/linux/memory_spec.rb b/spec/unit/plugins/linux/memory_spec.rb
index 694652f2..cb2fe1b8 100644
--- a/spec/unit/plugins/linux/memory_spec.rb
+++ b/spec/unit/plugins/linux/memory_spec.rb
@@ -59,144 +59,144 @@ describe Ohai::System, "Linux memory plugin" do
it "should get total memory" do
@plugin.run
- expect(@plugin[:memory][:total]).to eql(131932120 / 1024.0)
+ expect(@plugin[:memory][:total]).to eql("131932120kB")
end
it "should get free memory" do
@plugin.run
- expect(@plugin[:memory][:free]).to eql(2269032 / 1024.0)
+ 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(646368 / 1024.0)
+ expect(@plugin[:memory][:buffers]).to eql("646368kB")
end
it "should get cache memory" do
@plugin.run
- expect(@plugin[:memory][:cached]).to eql(32346556 / 1024.0)
+ expect(@plugin[:memory][:cached]).to eql("32346556kB")
end
it "should get active memory" do
@plugin.run
- expect(@plugin[:memory][:active]).to eql(98595796 / 1024.0)
+ expect(@plugin[:memory][:active]).to eql("98595796kB")
end
it "should get inactive memory" do
@plugin.run
- expect(@plugin[:memory][:inactive]).to eql(18477320 / 1024.0)
+ expect(@plugin[:memory][:inactive]).to eql("18477320kB")
end
it "should get high_total memory" do
@plugin.run
- expect(@plugin[:memory][:high_total]).to eql(0.0)
+ 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(0.0)
+ 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(131932120 / 1024.0)
+ 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(2269032 / 1024.0)
+ expect(@plugin[:memory][:low_free]).to eql("2269032kB")
end
it "should get dirty memory" do
@plugin.run
- expect(@plugin[:memory][:dirty]).to eql(3212 / 1024.0)
+ expect(@plugin[:memory][:dirty]).to eql("3212kB")
end
it "should get writeback memory" do
@plugin.run
- expect(@plugin[:memory][:writeback]).to eql(0.0)
+ expect(@plugin[:memory][:writeback]).to eql("0kB")
end
it "should get anon_pages memory" do
@plugin.run
- expect(@plugin[:memory][:anon_pages]).to eql(84082132 / 1024.0)
+ expect(@plugin[:memory][:anon_pages]).to eql("84082132kB")
end
it "should get mapped memory" do
@plugin.run
- expect(@plugin[:memory][:mapped]).to eql(3445224 / 1024.0)
+ expect(@plugin[:memory][:mapped]).to eql("3445224kB")
end
it "should get slab memory" do
@plugin.run
- expect(@plugin[:memory][:slab]).to eql(9892096 / 1024.0)
+ expect(@plugin[:memory][:slab]).to eql("9892096kB")
end
it "should get slab_reclaimable memory" do
@plugin.run
- expect(@plugin[:memory][:slab_reclaimable]).to eql(362636 / 1024.0)
+ 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(18860 / 1024.0)
+ 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(1759332 / 1024.0)
+ 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(0.0)
+ expect(@plugin[:memory][:nfs_unstable]).to eql("0kB")
end
it "should get bounce memory" do
@plugin.run
- expect(@plugin[:memory][:bounce]).to eql(0.0)
+ expect(@plugin[:memory][:bounce]).to eql("0kB")
end
it "should get commit_limit memory" do
@plugin.run
- expect(@plugin[:memory][:commit_limit]).to eql(148709328 / 1024.0)
+ 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(333717060 / 1024.0)
+ 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(34359738367 / 1024.0)
+ 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(276796 / 1024.0)
+ 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(34359461515 / 1024.0)
+ expect(@plugin[:memory][:vmalloc_chunk]).to eql("34359461515kB")
end
it "should get total swap" do
@plugin.run
- expect(@plugin[:memory][:swap][:total]).to eql(16777208 / 1024.0)
+ expect(@plugin[:memory][:swap][:total]).to eql("16777208kB")
end
it "should get cached swap" do
@plugin.run
- expect(@plugin[:memory][:swap][:cached]).to eql(312 / 1024.0)
+ expect(@plugin[:memory][:swap][:cached]).to eql("312kB")
end
it "should get free swap" do
@plugin.run
- expect(@plugin[:memory][:swap][:free]).to eql(14127356 / 1024.0)
+ expect(@plugin[:memory][:swap][:free]).to eql("14127356kB")
end