updated parse size
This commit is contained in:
@ -781,15 +781,18 @@ class SystemHealthMonitor:
|
||||
def _parse_size(self, size_str: str) -> float:
|
||||
"""Parse size string with units to bytes"""
|
||||
if not size_str or not isinstance(size_str, str):
|
||||
logger.debug(f"Invalid size string: {size_str}")
|
||||
return 0.0
|
||||
|
||||
size_str = size_str.strip().upper()
|
||||
logger.debug(f"Parsing size string: {size_str}")
|
||||
|
||||
# Match size with optional decimal and unit
|
||||
match = re.match(r'^([\d.]+)\s*([KMGT]B?)?$', size_str)
|
||||
if match:
|
||||
value = float(match.group(1))
|
||||
unit = match.group(2)
|
||||
logger.debug(f"Extracted value: {value}, unit: {unit}")
|
||||
|
||||
multipliers = {
|
||||
'K': 1024,
|
||||
@ -801,9 +804,11 @@ class SystemHealthMonitor:
|
||||
'GB': 1024**3,
|
||||
'TB': 1024**4
|
||||
}
|
||||
byte_value = value * multipliers.get(unit, 1)
|
||||
logger.debug(f"Converted size to bytes: {byte_value}")
|
||||
return byte_value
|
||||
|
||||
return value * multipliers.get(unit, 1) # Default to 1 for bytes
|
||||
|
||||
logger.debug(f"Failed to parse size string: {size_str}")
|
||||
return 0.0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user