mirror of
https://github.com/swizzin/swizzin_dashboard.git
synced 2024-11-10 08:52:34 +08:00
Fix iec vs si usage for unit conversion
This commit is contained in:
parent
412a5c4f86
commit
67958edbd9
2 changed files with 14 additions and 13 deletions
15
core/util.py
15
core/util.py
|
@ -263,16 +263,16 @@ def network_quota_usage(username):
|
|||
quota = json.loads(quota)
|
||||
try:
|
||||
total = int(quota['total'])
|
||||
totalh = GetHumanReadableB(total)
|
||||
totalh = GetHumanReadableBi(total)
|
||||
except:
|
||||
totalh = quota['total']
|
||||
try:
|
||||
free = int(quota['remaining'])
|
||||
freeh = GetHumanReadableB(free)
|
||||
freeh = GetHumanReadableBi(free)
|
||||
except:
|
||||
freeh = quota['remaining']
|
||||
used = int(quota['used'])
|
||||
usedh = GetHumanReadableB(used)
|
||||
usedh = GetHumanReadableBi(used)
|
||||
try:
|
||||
usage = '{0:.2f}'.format((used / total * 100))
|
||||
except:
|
||||
|
@ -288,13 +288,14 @@ def GetHumanReadableKiB(size,precision=2):
|
|||
size = size/1024.0 #apply the division
|
||||
return "%.*f %s"%(precision,size,suffixes[suffixIndex])
|
||||
|
||||
#KB function is unused -- check math before using
|
||||
def GetHumanReadableKB(size,precision=2):
|
||||
#https://stackoverflow.com/a/32009595
|
||||
suffixes=['KB','MB','GB','TB','PB']
|
||||
suffixIndex = 0
|
||||
while size > 1024 and suffixIndex < 4:
|
||||
while size > 1000 and suffixIndex < 4:
|
||||
suffixIndex += 1 #increment the index of the suffix
|
||||
size = size/1024.0 #apply the division
|
||||
size = size/1000.0 #apply the division
|
||||
return "%.*f %s"%(precision,size,suffixes[suffixIndex])
|
||||
|
||||
def GetHumanReadableBi(size,precision=2):
|
||||
|
@ -310,9 +311,9 @@ def GetHumanReadableB(size,precision=2):
|
|||
#https://stackoverflow.com/a/32009595
|
||||
suffixes=['B','KB','MB','GB','TB','PB']
|
||||
suffixIndex = 0
|
||||
while size > 1024 and suffixIndex < 4:
|
||||
while size > 1000 and suffixIndex < 4:
|
||||
suffixIndex += 1 #increment the index of the suffix
|
||||
size = size/1024.0 #apply the division
|
||||
size = size/1000.0 #apply the division
|
||||
return "%.*f %s"%(precision,size,suffixes[suffixIndex])
|
||||
|
||||
def get_nic_bytes(t, interface):
|
||||
|
|
12
swizzin.py
12
swizzin.py
|
@ -84,15 +84,15 @@ def current_speed(app):
|
|||
if tx_prev > 0:
|
||||
tx_speed = tx - tx_prev
|
||||
#print('TX: ', tx_speed, 'bps')
|
||||
tx_speed = str(GetHumanReadableB(tx_speed)) + "/s"
|
||||
tx_speed = str(GetHumanReadableBi(tx_speed)) + "/s"
|
||||
if rx_prev > 0:
|
||||
rx_speed = rx - rx_prev
|
||||
#print('RX: ', rx_speed, 'bps')
|
||||
rx_speed = str(GetHumanReadableB(rx_speed)) + "/s"
|
||||
rx_speed = str(GetHumanReadableBi(rx_speed)) + "/s"
|
||||
if total_prev > 0:
|
||||
total_speed = total - total_prev
|
||||
#print("TOTAL: ', total_speed, 'bps')
|
||||
total_speed = str(GetHumanReadableB(total_speed)) + "/s"
|
||||
total_speed = str(GetHumanReadableBi(total_speed)) + "/s"
|
||||
emit('speed', {'interface': interface, 'tx': tx_speed, 'rx': rx_speed, 'total': total_speed}, namespace='/websocket', broadcast=True)
|
||||
time.sleep(1)
|
||||
tx_prev = tx
|
||||
|
@ -369,9 +369,9 @@ def boot_time(user):
|
|||
@htpasswd.required
|
||||
def ram_stats(user):
|
||||
ramstats = dict((i.split()[0].rstrip(':'),int(i.split()[1])) for i in open('/proc/meminfo').readlines())
|
||||
ramtotal = GetHumanReadableKB(ramstats['MemTotal'])
|
||||
ramfree = GetHumanReadableKB(ramstats['MemAvailable'])
|
||||
ramused = GetHumanReadableKB(ramstats['MemTotal'] - ramstats['MemAvailable'])
|
||||
ramtotal = GetHumanReadableKiB(ramstats['MemTotal'])
|
||||
ramfree = GetHumanReadableKiB(ramstats['MemAvailable'])
|
||||
ramused = GetHumanReadableKiB(ramstats['MemTotal'] - ramstats['MemAvailable'])
|
||||
perutil = '{0:.2f}'.format((ramstats['MemTotal'] - ramstats['MemAvailable']) / ramstats['MemTotal'] * 100)
|
||||
return flask.jsonify({"ramtotal": ramtotal, "ramfree": ramfree, "ramused": ramused, "perutil": perutil})
|
||||
|
||||
|
|
Loading…
Reference in a new issue