From 6927415c4195f85e5d439fd246bb5823f6e8138a Mon Sep 17 00:00:00 2001 From: Accusys Date: Thu, 14 May 2026 14:59:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20health=20API=20=E2=80=94=20add=20build?= =?UTF-8?q?=5Ftimestamp=20+=20detailed=20resource=20status=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - build.rs: BUILD_TIMESTAMP from build time via `date -u` - GET /health: now returns build_timestamp - GET /health/detailed: returns build_timestamp + resources block (cpu_used/cpu_idle/memory/gpu usage) --- build.rs | 9 +++++++++ src/api/server.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/build.rs b/build.rs index e86a3be..66969d6 100644 --- a/build.rs +++ b/build.rs @@ -9,6 +9,15 @@ fn main() { .map(|s| s.trim().to_string()) .unwrap_or_else(|| "unknown".to_string()); + let timestamp = std::process::Command::new("date") + .args(["-u", "+%Y-%m-%dT%H:%M:%SZ"]) + .output() + .ok() + .and_then(|o| String::from_utf8(o.stdout).ok()) + .map(|s| s.trim().to_string()) + .unwrap_or_else(|| "unknown".to_string()); + println!("cargo:rustc-env=BUILD_VERSION={}", version); println!("cargo:rustc-env=BUILD_GIT_HASH={}", git_hash); + println!("cargo:rustc-env=BUILD_TIMESTAMP={}", timestamp); } diff --git a/src/api/server.rs b/src/api/server.rs index 22e6835..bd0eef8 100644 --- a/src/api/server.rs +++ b/src/api/server.rs @@ -16,6 +16,7 @@ use crate::core::cache::{keys, MongoCache, RedisCache}; use crate::core::config::REDIS_KEY_PREFIX; use crate::core::db::schema; use crate::core::db::{Database, PostgresDb, QdrantDb, RedisClient, VideoRecord, VideoStatus}; +use crate::worker::resources::SystemResources; use crate::core::text::tokenizer::tokenize_chinese_text; use crate::{Embedder, FileManager}; @@ -73,6 +74,7 @@ struct HealthResponse { status: String, version: String, build_git_hash: String, + build_timestamp: String, uptime_ms: u64, } @@ -371,8 +373,22 @@ struct DetailedHealthResponse { status: String, version: String, build_git_hash: String, + build_timestamp: String, uptime_ms: u64, services: ServiceHealth, + resources: ResourceStatus, +} + +#[derive(Debug, Serialize)] +struct ResourceStatus { + cpu_used_percent: f64, + cpu_idle_percent: f64, + memory_available_mb: u64, + memory_total_mb: u64, + memory_used_percent: f64, + gpu_available: bool, + gpu_utilization: Option, + gpu_memory_used_pct: Option, } #[derive(Debug, Serialize)] @@ -411,6 +427,7 @@ async fn health(State(state): State) -> Json { status: status.to_string(), version: env!("BUILD_VERSION").to_string(), build_git_hash: env!("BUILD_GIT_HASH").to_string(), + build_timestamp: env!("BUILD_TIMESTAMP").to_string(), uptime_ms: get_uptime_ms(), }) } @@ -431,10 +448,13 @@ async fn health_detailed(State(state): State) -> Json) -> Json