class Silw::Plugins::Mem
Meminfo - report the memory stats collected from a remote system, in bytes, rather than KBytes. For more details about meminfo see this featured article: /proc/meminfo Explained, at:
- http://www.redhat.com/advice/tips/meminfo.html
@return - a JSON containing the main memory stats
Attributes
mem[RW]
Public Instance Methods
run(args)
click to toggle source
# File lib/silw/plugins/mem.rb, line 14 def run(args) host = args[:at] if fixture_name = args[:fixture] mem = parse_meminfo File.read(fixture_name) else mem = parse_meminfo get_meminfo(host) end {:host => host, :mem => mem} end
Private Instance Methods
get_meminfo(remote, opts={})
click to toggle source
# File lib/silw/plugins/mem.rb, line 36 def get_meminfo(remote, opts={}) Net::SFTP.start(remote, @username, :keys => @pub_key ) do |scp| return scp.download!('/proc/meminfo') end end
parse_meminfo(txt)
click to toggle source
# File lib/silw/plugins/mem.rb, line 27 def parse_meminfo(txt) meminfo = txt.split(/\n/).collect{|x| x.strip} memtotal = 1_024 * meminfo[0].gsub(/[^0-9]/, "").to_f memfree = 1_024 * meminfo[1].gsub(/[^0-9]/, "").to_f memactive = 1_024 * meminfo[5].gsub(/[^0-9]/, "").to_f {:total => memtotal.round, :active => memactive.round, :free => memfree.round, :usagepercentage => ((memactive * 100) / memtotal).round} end