headless_lms_server/domain/system_health/
mod.rs1pub mod health_check;
4pub mod kubernetes;
5
6pub use health_check::{check_system_health, check_system_health_detailed};
7pub use kubernetes::{
8 get_cronjobs, get_deployments, get_events, get_ingresses, get_jobs, get_pod_disruption_budgets,
9 get_pod_logs, get_pods, get_services,
10};
11
12use serde::{Deserialize, Serialize};
13use std::collections::HashMap;
14
15use utoipa::ToSchema;
16
17#[derive(Debug, Serialize, Deserialize, ToSchema)]
18
19pub struct PodInfo {
20 pub name: String,
21 pub phase: String,
22 pub ready: Option<bool>,
23 pub labels: HashMap<String, String>,
24}
25
26#[derive(Debug, Serialize, Deserialize, ToSchema)]
27
28pub struct DeploymentInfo {
29 pub name: String,
30 pub replicas: i32,
31 pub ready_replicas: i32,
32 pub selector_labels: HashMap<String, String>,
33}
34
35#[derive(Debug, Serialize, Deserialize, ToSchema)]
36
37pub struct CronJobInfo {
38 pub name: String,
39 pub schedule: String,
40 pub last_schedule_time: Option<String>,
41}
42
43#[derive(Debug, Serialize, Deserialize, ToSchema)]
44
45pub struct JobInfo {
46 pub name: String,
47 pub succeeded: Option<i32>,
48 pub failed: Option<i32>,
49 pub active: Option<i32>,
50}
51
52#[derive(Debug, Serialize, Deserialize, ToSchema)]
53
54pub struct ServiceInfo {
55 pub name: String,
56 pub cluster_ip: Option<String>,
57 pub ports: Vec<ServicePortInfo>,
58}
59
60#[derive(Debug, Serialize, Deserialize, ToSchema)]
61
62pub struct ServicePortInfo {
63 pub name: Option<String>,
64 pub port: i32,
65 pub target_port: Option<String>,
66 pub protocol: Option<String>,
67}
68
69#[derive(Debug, Serialize, Deserialize, ToSchema)]
70
71pub struct EventInfo {
72 pub name: String,
73 pub reason: Option<String>,
74 pub message: Option<String>,
75 pub type_: Option<String>,
76 pub first_timestamp: Option<String>,
77 pub last_timestamp: Option<String>,
78 pub count: Option<i32>,
79 pub involved_object_kind: Option<String>,
80 pub involved_object_name: Option<String>,
81}
82
83#[derive(Debug, Serialize, Deserialize, ToSchema)]
84
85pub struct IngressInfo {
86 pub name: String,
87 pub hosts: Vec<String>,
88 pub paths: Vec<String>,
89 pub class_name: Option<String>,
90}
91
92#[derive(Debug, Serialize, Deserialize, ToSchema)]
93
94pub struct PodDisruptionBudgetInfo {
95 pub name: String,
96 pub current_healthy: i32,
97 pub desired_healthy: i32,
98 pub disruptions_allowed: i32,
99 pub expected_pods: i32,
100 pub selector_labels: HashMap<String, String>,
101}
102
103#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, ToSchema)]
104#[serde(rename_all = "lowercase")]
105pub enum HealthStatus {
106 Healthy,
107 Warning,
108 Error,
109}
110
111#[derive(Debug, Serialize, Deserialize, ToSchema)]
112
113pub struct SystemHealthStatus {
114 pub status: HealthStatus,
115 pub issues: Vec<String>,
116}
117
118pub fn get_namespace() -> String {
119 std::env::var("POD_NAMESPACE").unwrap_or_else(|_| "default".to_string())
120}