1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-22 17:57:46 +03:00

bug #182: Columns with KB units are rounded to MB, GB or TB for readability

This commit is contained in:
Carlos Martín 2010-08-26 16:59:27 +02:00 committed by Javi Fontan
parent 8a3f88801c
commit 86c2dad68c
3 changed files with 23 additions and 0 deletions

View File

@ -20,6 +20,24 @@ require 'OpenNebula'
# CONSOLE UTILITIES #
#####################
BinarySufix = ["K", "M", "G", "T" ]
def humanize_size(value)
i=0
while value > 1024 && i < 3 do
value /= 1024.0
i+=1
end
value = (value * 10).round / 10.0
value = value.to_i if value - value.round == 0
st = value.to_s + BinarySufix[i]
return st
end
# Sets bold font
def scr_bold
print "\33[1m"
@ -122,6 +140,8 @@ class ShowTable
dat=d[c]
col=@columns[c]
dat = humanize_size( Float(dat) ) if( @table[col][:kbytes] )
format_data(col, dat) if @table[col]
}.join(' ')
}.join("\n")

View File

@ -87,12 +87,14 @@ ShowTableHost={
:name => "TMEM",
:desc => "Total memory",
:size => 7,
:kbytes => true,
:proc => lambda {|d,e| d["HOST_SHARE/MAX_MEM"] }
},
:fmem => {
:name => "FMEM",
:desc => "Free memory",
:size => 7,
:kbytes => true,
:proc => lambda {|d,e| d["HOST_SHARE/FREE_MEM"] }
},
:stat => {

View File

@ -75,6 +75,7 @@ ShowTableVM={
:name => "MEM",
:desc => "Memory used by the VM",
:size => 7,
:kbytes => true,
:proc => lambda {|d,e| d["MEMORY"] }
},
:hostname => {