add more docker stats (#14767)

This commit is contained in:
Henne Van Och
2023-03-01 01:02:01 +01:00
committed by GitHub
parent f023d37cfc
commit 2140ff21c5
11 changed files with 639 additions and 41 deletions

View File

@@ -125,4 +125,26 @@ class Number
return round($part / $total * 100, $precision);
}
/**
* This converts a memory size containing the unit to bytes. example 1 MiB to 1048576 bytes
*/
public static function convertToBytes(string $from): ?int
{
$units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
$number = floatval(substr($from, 0, -3));
$suffix = substr($from, -3);
//B or no suffix
if (is_numeric(substr($suffix, 0, 1))) {
return (int) $from;
}
$exponent = array_flip($units)[$suffix] ?? null;
if ($exponent === null) {
return null;
}
return (int) ($number * (1024 ** $exponent));
}
}