Check if system has enough resources for new operations
(self)
| 68 | self.logger.error(f"Error getting available memory: {e}") |
| 69 | return 0 |
| 70 | |
| 71 | def is_system_healthy(self): |
| 72 | """Check if system has enough resources for new operations""" |
| 73 | mem_percent = self.get_memory_usage() |
| 74 | cpu_percent = self.get_cpu_usage() |
| 75 | |
| 76 | if mem_percent >= self.memory_critical_threshold: |
| 77 | current_time = time.time() |
| 78 | if current_time - self.last_warning_time > self.warning_interval: |
| 79 | self.logger.critical( |
| 80 | f"CRITICAL: Memory usage at {mem_percent:.1f}% - " |
| 81 | f"BLOCKING new operations to prevent system hang!" |
| 82 | ) |
| 83 | self.last_warning_time = current_time |
| 84 | return False |
| 85 | |
| 86 | if cpu_percent >= self.cpu_critical_threshold: |
| 87 | current_time = time.time() |
| 88 | if current_time - self.last_warning_time > self.warning_interval: |
| 89 | self.logger.critical( |
| 90 | f"CRITICAL: CPU usage at {cpu_percent:.1f}% - " |
| 91 | f"BLOCKING new operations to prevent system hang!" |
| 92 | ) |
| 93 | self.last_warning_time = current_time |
| 94 | return False |
| 95 | |
| 96 | if mem_percent >= self.memory_warning_threshold: |
| 97 | current_time = time.time() |
| 98 | if current_time - self.last_warning_time > self.warning_interval: |
| 99 | self.logger.warning( |
| 100 | f"WARNING: Memory usage at {mem_percent:.1f}% - " |
| 101 | f"System may slow down" |
| 102 | ) |
| 103 | self.last_warning_time = current_time |
| 104 | |
| 105 | return True |
| 106 | |
| 107 | def can_start_operation(self, operation_name="operation", min_memory_mb=50): |
no test coverage detected