MCPcopy Index your code
hub / github.com/InfinitiBit/graphbit / health_check

Function health_check

python/src/lib.rs:200–248  ·  view source on GitHub ↗
(py: Python<'_>)

Source from the content-addressed store, hash-verified

198/// - Core library health
199#[pyfunction]
200fn health_check(py: Python<'_>) -> PyResult<Bound<'_, PyDict>> {
201 let dict = PyDict::new(py);
202 let mut overall_healthy = true;
203
204 // Check runtime health
205 let runtime_healthy = runtime::is_runtime_initialized();
206 dict.set_item("runtime_healthy", runtime_healthy)?;
207 if !runtime_healthy {
208 overall_healthy = false;
209 warn!("Runtime is not properly initialized");
210 }
211
212 // Check if we can get runtime stats
213 if let Some(stats) = runtime::get_runtime_stats() {
214 dict.set_item("runtime_uptime_ok", stats.uptime.as_secs() > 0)?;
215 dict.set_item("worker_threads_ok", stats.worker_threads > 0)?;
216 } else {
217 dict.set_item("runtime_stats_available", false)?;
218 overall_healthy = false;
219 }
220
221 // Memory check (basic)
222 let available_memory_mb = if let Ok(sys_info) = sys_info::mem_info() {
223 dict.set_item("total_memory_mb", sys_info.total / 1024)?;
224 dict.set_item("available_memory_mb", sys_info.avail / 1024)?;
225 sys_info.avail / 1024
226 } else {
227 dict.set_item("memory_info_available", false)?;
228 1024 // Assume 1GB if we can't detect
229 };
230
231 let memory_healthy = available_memory_mb > 100; // At least 100MB
232 dict.set_item("memory_healthy", memory_healthy)?;
233 if !memory_healthy {
234 overall_healthy = false;
235 warn!("Low available memory: {} MB", available_memory_mb);
236 }
237
238 dict.set_item("overall_healthy", overall_healthy)?;
239 dict.set_item("timestamp", chrono::Utc::now().timestamp())?;
240
241 if overall_healthy {
242 info!("Health check passed");
243 } else {
244 warn!("Health check failed - some components are unhealthy");
245 }
246
247 Ok(dict)
248}
249
250/// Configure the global runtime with custom settings
251///

Callers 2

test_health_checkMethod · 0.85

Calls 2

is_runtime_initializedFunction · 0.85
get_runtime_statsFunction · 0.85

Tested by 2

test_health_checkMethod · 0.68