mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
add more docker stats (#14767)
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user