Get comprehensive system status
(self)
| 150 | |
| 151 | return False |
| 152 | |
| 153 | def get_system_status(self): |
| 154 | """Get comprehensive system status""" |
| 155 | if not _HAS_PSUTIL: |
| 156 | return { |
| 157 | 'memory': {'percent': 0, 'status': 'ok', 'total_mb': 0, 'available_mb': 999, 'used_mb': 0}, |
| 158 | 'cpu': {'percent': 0, 'status': 'ok'}, |
| 159 | 'processes': 0, 'threads': 0, |
| 160 | 'healthy': True |
| 161 | } |
| 162 | try: |
| 163 | mem = psutil.virtual_memory() |
| 164 | cpu_percent = psutil.cpu_percent(interval=0.5) |
| 165 | |
| 166 | # Get process count |
| 167 | process_count = len(psutil.pids()) |
| 168 | |
| 169 | # Get thread count (current process) |
| 170 | try: |
| 171 | thread_count = psutil.Process().num_threads() |
| 172 | except: |
| 173 | thread_count = 0 |
| 174 | |
| 175 | status = { |
| 176 | 'memory': { |
| 177 | 'total_mb': mem.total / (1024 * 1024), |
| 178 | 'available_mb': mem.available / (1024 * 1024), |
| 179 | 'used_mb': mem.used / (1024 * 1024), |
| 180 | 'percent': mem.percent, |
| 181 | 'status': self._get_status_level(mem.percent, |
| 182 | self.memory_warning_threshold, |
| 183 | self.memory_critical_threshold) |
| 184 | }, |
| 185 | 'cpu': { |
| 186 | 'percent': cpu_percent, |
| 187 | 'status': self._get_status_level(cpu_percent, |
| 188 | self.cpu_warning_threshold, |
| 189 | self.cpu_critical_threshold) |
| 190 | }, |
| 191 | 'processes': process_count, |
| 192 | 'threads': thread_count, |
| 193 | 'healthy': self.is_system_healthy() |
| 194 | } |
| 195 | |
| 196 | return status |
| 197 | |
| 198 | except Exception as e: |
| 199 | self.logger.error(f"Error getting system status: {e}") |
| 200 | return { |
| 201 | 'memory': {'percent': 0, 'status': 'unknown'}, |
| 202 | 'cpu': {'percent': 0, 'status': 'unknown'}, |
| 203 | 'healthy': True # Fail open if we can't check |
| 204 | } |
| 205 | |
| 206 | def get_power_status(self): |
no test coverage detected