mirror of
https://github.com/unraid/webgui.git
synced 2026-04-27 05:19:44 -05:00
Add totals to docker container size calculation
This commit is contained in:
@@ -26,16 +26,18 @@ function autoscale($value) {
|
||||
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 ? ',' : '').' '.$unit[$base];
|
||||
}
|
||||
function align($text, $w=13) {
|
||||
return sprintf("%{$w}s",$text);
|
||||
}
|
||||
|
||||
function gap($text) {
|
||||
return preg_replace('/([kMGTPEZY]?B)$/'," $1",$text);
|
||||
}
|
||||
|
||||
function align($text, $w=13) {
|
||||
if ($w>0) $text = gap($text);
|
||||
return sprintf("%{$w}s",$text);
|
||||
function byteval($data) {
|
||||
global $unit;
|
||||
[$value,$base] = explode(' ',gap($data));
|
||||
return $value*pow(1000,array_search($base,$unit));
|
||||
}
|
||||
|
||||
exec("docker ps -sa --format='{{.Names}}|{{.Size}}'",$container);
|
||||
@@ -44,9 +46,16 @@ echo str_repeat('-',69)."\n";
|
||||
foreach ($container as $ct) {
|
||||
[$name,$size] = explode('|',$ct);
|
||||
[$writable,$dummy,$total] = explode(' ',str_replace(['(',')'],'',$size));
|
||||
[$value,$base] = explode(' ',gap($total));
|
||||
$list[] = ['name' => $name, 'total' => $value*pow(1000,array_search($base,$unit)), 'writable' => $writable, 'log' => (exec("docker inspect --format='{{.LogPath}}' $name|xargs du -b 2>/dev/null |cut -f1")) ?: "0"];
|
||||
$list[] = ['name' => $name, 'total' => byteval($total), 'writable' => byteval($writable), 'log' => (exec("docker inspect --format='{{.LogPath}}' $name|xargs du -b 2>/dev/null |cut -f1")) ?: "0"];
|
||||
}
|
||||
$sum = ['total' => 0, 'writable' => 0, 'log' => 0];
|
||||
array_multisort(array_column($list,'total'),SORT_DESC,$list); // sort on container size
|
||||
foreach ($list as $ct) echo align($ct['name'],-30).align(autoscale($ct['total'])).align($ct['writable']).align(autoscale($ct['log']))."\n";
|
||||
foreach ($list as $ct) {
|
||||
echo align($ct['name'],-30).align(autoscale($ct['total'])).align(autoscale($ct['writable'])).align(autoscale($ct['log']))."\n";
|
||||
$sum['total'] += $ct['total'];
|
||||
$sum['writable'] += $ct['writable'];
|
||||
$sum['log'] += $ct['log'];
|
||||
}
|
||||
echo str_repeat('-',69)."\n";
|
||||
echo align(_('Total size'),-30).align(autoscale($sum['total'])).align(autoscale($sum['writable'])).align(autoscale($sum['log']))."\n";
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user