fix: #331 admin info version,uptime

This commit is contained in:
weisd
2025-04-23 16:34:39 +08:00
parent fff7e5f827
commit cf2ed47fe8
7 changed files with 46 additions and 6 deletions
+22 -3
View File
@@ -1,6 +1,6 @@
use crate::{
disk::endpoint::Endpoint,
global::GLOBAL_Endpoints,
global::{GLOBAL_Endpoints, GLOBAL_BOOT_TIME},
heal::{
data_usage::{load_data_usage_from_backend, DATA_USAGE_CACHE_NAME, DATA_USAGE_ROOT},
data_usage_cache::DataUsageCache,
@@ -22,12 +22,16 @@ use protos::{
};
use std::{
collections::{HashMap, HashSet},
time::{SystemTime, UNIX_EPOCH},
time::SystemTime,
};
use time::OffsetDateTime;
use tonic::Request;
use tracing::warn;
use shadow_rs::shadow;
shadow!(build);
// pub const ITEM_OFFLINE: &str = "offline";
// pub const ITEM_INITIALIZING: &str = "initializing";
// pub const ITEM_ONLINE: &str = "online";
@@ -140,8 +144,12 @@ pub async fn get_local_server_property() -> ServerProperties {
let mut props = ServerProperties {
endpoint: addr,
uptime: SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
uptime: SystemTime::now()
.duration_since(*GLOBAL_BOOT_TIME.get().unwrap())
.unwrap_or_default()
.as_secs(),
network,
version: get_commit_id(),
..Default::default()
};
@@ -356,3 +364,14 @@ async fn get_pools_info(all_disks: &[Disk]) -> Result<HashMap<i32, HashMap<i32,
}
Ok(pools_info)
}
#[allow(clippy::const_is_empty)]
pub fn get_commit_id() -> String {
if !build::TAG.is_empty() {
build::TAG.to_string()
} else if !build::SHORT_COMMIT.is_empty() {
format!("@{}", build::SHORT_COMMIT)
} else {
build::PKG_VERSION.to_string()
}
}