MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / get_system_status

Method get_system_status

resource_monitor.py:152–203  ·  view source on GitHub ↗

Get comprehensive system status

(self)

Source from the content-addressed store, hash-verified

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):

Callers 1

log_system_statusMethod · 0.95

Calls 3

_get_status_levelMethod · 0.95
is_system_healthyMethod · 0.95
errorMethod · 0.80

Tested by

no test coverage detected