From ed5b0cab5250663e6a775b679f8afb55218bbfc6 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Sun, 9 Mar 2025 17:43:49 -0400 Subject: [PATCH] Better exclusions --- hwmonDaemon.py | 102 ++++++++++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 40 deletions(-) diff --git a/hwmonDaemon.py b/hwmonDaemon.py index 0c5085c..31a0ee5 100644 --- a/hwmonDaemon.py +++ b/hwmonDaemon.py @@ -50,7 +50,18 @@ class SystemHealthMonitor: 'PING_TIMEOUT': 1, 'PING_COUNT': 1 }, - 'EXCLUDED_MOUNTS': ['/media', '/mnt/pve/mediafs'] + 'EXCLUDED_MOUNTS': [ + '/media', + '/mnt/pve/mediafs', + '/opt/metube_downloads' + ], + 'EXCLUDED_PATTERNS': [ + r'/media.*', + r'/mnt/pve/mediafs.*', + r'.*/media$', + r'.*mediafs.*', + r'.*/downloads.*' + ] } TICKET_TEMPLATES = { 'ACTION_TYPE': { @@ -753,6 +764,18 @@ class SystemHealthMonitor: return list(disks) + def _is_excluded_mount(self, mountpoint: str) -> bool: + """Check if a mountpoint should be excluded from monitoring.""" + # Check exact matches + if mountpoint in self.CONFIG['EXCLUDED_MOUNTS']: + return True + + # Check patterns + for pattern in self.CONFIG['EXCLUDED_PATTERNS']: + if re.match(pattern, mountpoint): + return True + return False + def _is_physical_disk(self, device_path): """ Check if the device is a physical disk, excluding logical volumes and special devices. @@ -1358,47 +1381,46 @@ class SystemHealthMonitor: try: parts = fs_line.split() if len(parts) >= 6: - if parts[5] in self.CONFIG['EXCLUDED_MOUNTS'] or any(excluded in parts[5] for excluded in self.CONFIG['EXCLUDED_MOUNTS']): - continue + if parts[5] and not self._is_excluded_mount(parts[5]): - # Convert size strings to comparable values - total = parts[2] - used = parts[3] - avail = parts[4] - - # Calculate usage percentage - total_bytes = self._convert_size_to_bytes(total) - used_bytes = self._convert_size_to_bytes(used) - usage_percent = int((used_bytes / total_bytes) * 100) - - filesystem = { - 'mountpoint': parts[5], - 'total': total, - 'used': used, - 'available': avail, - 'usage_percent': usage_percent - } - - if self.dry_run: - logger.debug(f"Container {vmid} filesystem details:") - logger.debug(f" Mountpoint: {filesystem['mountpoint']}") - logger.debug(f" Usage: {used}/{total} ({usage_percent}%)") - - if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']: - lxc_health['status'] = 'CRITICAL' - issue = f"LXC {vmid} critical storage usage: {usage_percent}% on {parts[5]}" - lxc_health['issues'].append(issue) - if self.dry_run: - logger.debug(f"Critical issue detected: {issue}") - elif usage_percent >= self.CONFIG['THRESHOLDS']['DISK_WARNING']: - if lxc_health['status'] != 'CRITICAL': - lxc_health['status'] = 'WARNING' - issue = f"LXC {vmid} high storage usage: {usage_percent}% on {parts[5]}" - lxc_health['issues'].append(issue) - if self.dry_run: - logger.debug(f"Warning issue detected: {issue}") + # Convert size strings to comparable values + total = parts[2] + used = parts[3] + avail = parts[4] - container_info['filesystems'].append(filesystem) + # Calculate usage percentage + total_bytes = self._convert_size_to_bytes(total) + used_bytes = self._convert_size_to_bytes(used) + usage_percent = int((used_bytes / total_bytes) * 100) + + filesystem = { + 'mountpoint': parts[5], + 'total': total, + 'used': used, + 'available': avail, + 'usage_percent': usage_percent + } + + if self.dry_run: + logger.debug(f"Container {vmid} filesystem details:") + logger.debug(f" Mountpoint: {filesystem['mountpoint']}") + logger.debug(f" Usage: {used}/{total} ({usage_percent}%)") + + if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']: + lxc_health['status'] = 'CRITICAL' + issue = f"LXC {vmid} critical storage usage: {usage_percent}% on {parts[5]}" + lxc_health['issues'].append(issue) + if self.dry_run: + logger.debug(f"Critical issue detected: {issue}") + elif usage_percent >= self.CONFIG['THRESHOLDS']['DISK_WARNING']: + if lxc_health['status'] != 'CRITICAL': + lxc_health['status'] = 'WARNING' + issue = f"LXC {vmid} high storage usage: {usage_percent}% on {parts[5]}" + lxc_health['issues'].append(issue) + if self.dry_run: + logger.debug(f"Warning issue detected: {issue}") + + container_info['filesystems'].append(filesystem) except Exception as e: if self.dry_run: logger.debug(f"Error processing filesystem line for container {vmid}: {str(e)}")