This commit is contained in:
kyg516 2016-09-26 18:06:53 +09:00
parent 21a647dff0
commit 962f6ff8f7
3 changed files with 56 additions and 33 deletions

View File

@ -9,15 +9,19 @@ module ApplicationHelper
output = `#{command}`.split("\n") output = `#{command}`.split("\n")
output.each do |t| output.each do |t|
next if t.equal? output.first next if t.equal? output.first
s = t.split(' ') begin
df_each['Filesystem'] = s[0] s = t.split(' ')
df_each['Size'] = s[1] df_each['Filesystem'] = s[0]
df_each['Used'] = s[2] df_each['Size'] = s[1]
df_each['Avail'] = s[3] df_each['Used'] = s[2]
df_each['Use%'] = s[4] df_each['Avail'] = s[3]
df_each['Mounted on'] = s[5] df_each['Use%'] = s[4]
df << df_each df_each['Mounted on'] = s[5]
df_each = Hash.new df << df_each
df_each = Hash.new
rescue => ex
puts ex
end
end end
return df return df
end end
@ -27,12 +31,10 @@ module ApplicationHelper
volume = Hash.new volume = Hash.new
node = Node.take node = Node.take
df = get_df df = get_df
# error check : node is nil # error check : node is nil
if node.nil? if node.nil?
return volumes return volumes
end end
command = String.new command = String.new
command << "sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume info" command << "sshpass -p#{node.user_password} ssh #{node.user_name}@#{node.host_ip} gluster volume info"
puts command puts command
@ -60,16 +62,23 @@ module ApplicationHelper
def files(dir) def files(dir)
files = Array.new files = Array.new
file = Hash.new file = Hash.new
output = `ls #{dir} -l`.split("\n") command = String.new
command << "ls #{dir} -l"
puts command
output = `#{command}`.split("\n")
output.each do |t| output.each do |t|
next if t.equal? output.first next if t.equal? output.first
s = t.split(" ") begin
file["auth"] = s[0] s = t.split(" ")
file["size"] = s[4] file["auth"] = s[0]
file["date"] = s[5] + " " + s[6] + " " + s[7] file["size"] = s[4]
file["name"] = s[8] file["date"] = s[5] + " " + s[6] + " " + s[7]
files << file file["name"] = s[8]
file = Hash.new files << file
file = Hash.new
rescue => ex
puts ex
end
end end
return files return files
end end

View File

@ -4,23 +4,37 @@ module HomeHelper
du = Array.new du = Array.new
du_each = Hash.new du_each = Hash.new
command = String.new command = String.new
avail = 0.0
if dir.eql? "/" if dir.eql? "/"
command = "sudo df /" command = "sudo df /"
s = `#{command}`.split("\n")[1].split(" ") s = `#{command}`.split("\n")[1].split(" ")
avail = s[2].to_f + s[3].to_f avail = s[2].to_f + s[3].to_f
else else
command << "sudo du -s #{dir}" command << "sudo du -s #{dir}"
avail = `#{command}`.split(" ")[0].to_f begin
avail = `#{command}`.split(" ")[0].to_f
rescue
# some directory is not connected
avail = `#{command}`.split(" ")[1].to_f
end
end end
command << "sudo du -s #{dir}/*" command << "sudo du -s #{dir}/*"
puts command puts command
output = `#{command}`.split("\n") output = `#{command}`.split("\n")
output.each do |t| output.each do |t|
du_each['usage'] = t.split(" ")[0].to_f / avail begin
du_each['file_name'] = t.split(" ")[1].split("/").last du_each['usage'] = t.split(" ")[0].to_f / avail
du << du_each du_each['file_name'] = t.split(" ")[1].split("/").last
du_each = Hash.new du << du_each
du_each = Hash.new
rescue
# directory is not connected
du_each['usage'] = 0.0
du_each['file_name'] = t.split(" ")[1].split("/").last.split("'")[0]
du << du_each
du_each = Hash.new
end
end end
return du return du
end end

View File

@ -137,7 +137,7 @@
<tbody id="datatable_body"> <tbody id="datatable_body">
<tr> <tr>
<td> <td>
<a style='cursor: pointer' onclick="change_upper('<%=@current_dir%>')"><i class="fa fa-reply"></i></a> <a style='cursor: pointer' onclick="change_upper('<%= @current_dir %>')"><i class="fa fa-reply"></i></a>
<%= @current_dir %> <%= @current_dir %>
<a class='pull-right' href="#popup_mkdir"><i class="fa fa-plus"></i><i class="fa fa-folder"></i></a> <a class='pull-right' href="#popup_mkdir"><i class="fa fa-plus"></i><i class="fa fa-folder"></i></a>
</td> </td>
@ -431,14 +431,6 @@ function change_directory(directory){
} }
</script> </script>
<!-- On document ready -->
<script>
$('document').ready(function() {
$('#datatable').dataTable( {"bSort": false});
draw_chart();
});
</script>
<!-- Doughnut Chart --> <!-- Doughnut Chart -->
<script> <script>
function draw_chart() { function draw_chart() {
@ -476,3 +468,11 @@ function draw_chart() {
}; };
</script> </script>
<!-- /Doughnut Chart --> <!-- /Doughnut Chart -->
<!-- On document ready -->
<script>
$('document').ready(function() {
$('#datatable').dataTable( {"bSort": false});
draw_chart();
});
</script>