From 519a30e11e664372b484e3c1981ad8475306b4a8 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sun, 9 Mar 2025 21:47:41 -0400 Subject: [PATCH] update parsing --- hwmonDaemon.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index b360263..f60d0b7 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -782,16 +782,14 @@ class SystemHealthMonitor: """Parse size string with units to bytes""" if not size_str or not isinstance(size_str, str): return 0.0 - - # Remove any whitespace and convert to uppercase for consistent handling + size_str = size_str.strip().upper() - - # Handle values with decimal points (like 192.2M) - match = re.match(r'^([\d.]+)\s*([KMGT])?B?$', size_str) + + match = re.match(r'^([\d.]+)\s*([KMGT])?B?$', size_str) # Corrected regex if match: value = float(match.group(1)) unit = match.group(2) if match.group(2) else 'B' - + multipliers = { 'B': 1, 'K': 1024, @@ -799,9 +797,9 @@ class SystemHealthMonitor: 'G': 1024**3, 'T': 1024**4 } - + return value * multipliers[unit] - + return 0.0 def _is_physical_disk(self, device_path): @@ -1424,9 +1422,9 @@ class SystemHealthMonitor: avail_bytes = self._parse_size(filesystem['available']) # Store both human readable and byte values - filesystem['total_bytes'] = total_bytes - filesystem['used_bytes'] = used_bytes - filesystem['avail_bytes'] = avail_bytes + filesystem['total_bytes'] = self._parse_size(filesystem['total_space']) + filesystem['used_bytes'] = self._parse_size(filesystem['used_space']) + filesystem['avail_bytes'] = self._parse_size(filesystem['available']) if filesystem['usage_percent'] >= self.CONFIG['THRESHOLDS']['LXC_CRITICAL']: lxc_health['status'] = 'CRITICAL'