gluster-web-interface/app/helpers/home_helper.rb

29 lines
752 B
Ruby
Raw Normal View History

2016-08-20 06:41:37 +00:00
module HomeHelper
2016-09-24 09:00:27 +00:00
def get_du(dir)
du = Array.new
du_each = Hash.new
command = String.new
if dir.eql? "/"
command = "sudo df /"
s = `#{command}`.split("\n")[1].split(" ")
avail = s[2].to_f + s[3].to_f
else
command << "sudo du -s #{dir}"
avail = `#{command}`.split(" ")[0].to_f
end
command << "sudo du -s #{dir}/*"
puts command
output = `#{command}`.split("\n")
output.each do |t|
du_each['usage'] = t.split(" ")[0].to_f / avail
du_each['file_name'] = t.split(" ")[1].split("/").last
du << du_each
du_each = Hash.new
end
return du
end
2016-08-20 06:41:37 +00:00
end