container_size: rename $unit to $units

This commit is contained in:
bergware
2023-10-17 09:51:28 +02:00
parent 5adacfba98
commit cd190843ab

View File

@@ -22,7 +22,7 @@ $_SERVER['REQUEST_URI'] = 'docker';
$login_locale = _var($display,'locale');
require_once "$docroot/webGui/include/Translations.php";
$unit = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
$units = ['B','kB','MB','GB','TB','PB','EB','ZB','YB'];
$list = [];
function write(...$messages){
@@ -40,13 +40,13 @@ function write(...$messages){
curl_close($com);
}
function autoscale($value) {
global $unit;
$size = count($unit);
global $units;
$size = count($units);
$base = $value ? floor(log($value, 1000)) : 0;
if ($base>=$size) $base = $size-1;
$value /= pow(1000, $base);
$decimals = $base ? ($value>=100 ? 0 : ($value>=10 ? 1 : (round($value*100)%100===0 ? 0 : 2))) : 0;
return number_format($value, $decimals, '.', $value>9999 ? ',' : '').' '.$unit[$base];
return number_format($value, $decimals, '.', $value>9999 ? ',' : '').' '.$units[$base];
}
function align($text, $w=25) {
return $text.str_repeat(' ',$w-min(strlen($text),$w-1));
@@ -55,9 +55,9 @@ function gap($text) {
return preg_replace('/([kMGTPEZY]?B)$/'," $1",$text);
}
function byteval($data) {
global $unit;
global $units;
[$value,$base] = explode(' ',gap($data));
return $value*pow(1000,array_search($base,$unit));
return $value*pow(1000,array_search($base,$units));
}
exec("docker ps -sa --format='{{.Names}}|{{.Size}}'",$container);