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