Initial commit

This commit is contained in:
redclawsystems
2026-03-04 00:08:42 +00:00
commit 4d88dc0584
4449 changed files with 1556714 additions and 0 deletions
@@ -0,0 +1,62 @@
//! Health check management.
use crate::MonitoringResult;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
/// Health check status.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum HealthStatus {
Healthy,
Degraded,
Unhealthy,
Unknown,
}
/// Health check trait.
#[async_trait]
pub trait HealthCheck: Send + Sync {
async fn check(&self) -> MonitoringResult<HealthStatus>;
fn name(&self) -> &str;
}
/// Health manager for coordinating health checks.
pub struct HealthManager {
checks: Vec<Box<dyn HealthCheck>>,
}
impl std::fmt::Debug for HealthManager {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("HealthManager")
.field("checks_count", &self.checks.len())
.finish()
}
}
impl HealthManager {
pub async fn new() -> MonitoringResult<Self> {
Ok(Self { checks: Vec::new() })
}
pub fn is_enabled(&self) -> bool {
true
}
pub async fn run_all_checks(&self) -> MonitoringResult<()> {
for check in &self.checks {
match check.check().await {
Ok(status) => {
tracing::debug!("Health check '{}': {:?}", check.name(), status);
}
Err(e) => {
tracing::warn!("Health check '{}' failed: {}", check.name(), e);
}
}
}
Ok(())
}
pub async fn overall_status(&self) -> MonitoringResult<HealthStatus> {
Ok(HealthStatus::Healthy)
}
}