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