diff --git a/sentinel-core/Cargo.toml b/sentinel-core/Cargo.toml index 944718c..f1a4a65 100644 --- a/sentinel-core/Cargo.toml +++ b/sentinel-core/Cargo.toml @@ -66,6 +66,7 @@ k8s-openapi = { version = "0.16.0", default-features = false, features = [ "v1_25", ], optional = true } schemars = { version = "0.8.8", optional = true } +dirs = "5.0.1" [target.'cfg(not(target_arch="wasm32"))'.dependencies] # cannot add "wasm-bindgen" feature to uuid, diff --git a/sentinel-core/src/core/config/base.rs b/sentinel-core/src/core/config/base.rs index b587b55..2485f2d 100644 --- a/sentinel-core/src/core/config/base.rs +++ b/sentinel-core/src/core/config/base.rs @@ -244,3 +244,11 @@ pub fn metric_stat_sample_count() -> u32 { .try_with(|c| c.borrow().config.stat.sample_count) .unwrap() } + +#[inline] +pub fn get_default_log_dir() -> String { + match dirs::home_dir() { + Some(path) => path.join(LOG_METRICS_DIR).to_string_lossy().to_string(), + None => LOG_METRICS_DIR.to_string(), + } +} diff --git a/sentinel-core/src/core/config/entity.rs b/sentinel-core/src/core/config/entity.rs index 19c8496..fa507b8 100644 --- a/sentinel-core/src/core/config/entity.rs +++ b/sentinel-core/src/core/config/entity.rs @@ -1,4 +1,5 @@ use super::constant::*; +use crate::config::get_default_log_dir; use crate::{ base::{check_validity_for_reuse_statistic, constant::*, ResourceType}, Error, Result, @@ -38,7 +39,7 @@ impl Default for LogMetricConfig { fn default() -> Self { LogMetricConfig { use_pid: true, - dir: LOG_METRICS_DIR.into(), + dir: get_default_log_dir(), single_file_max_size: SINGLE_FILE_MAX_SIZE, max_file_count: MAX_FILE_AMOUNT, flush_interval_sec: FLUSH_INTERVAL_SEC, diff --git a/sentinel-core/src/core/stat/resource_node.rs b/sentinel-core/src/core/stat/resource_node.rs index 45accf9..064b66c 100644 --- a/sentinel-core/src/core/stat/resource_node.rs +++ b/sentinel-core/src/core/stat/resource_node.rs @@ -60,6 +60,14 @@ impl ResourceNode { pub fn max_concurrency(&self) -> u32 { self.metric.max_concurrency() } + + pub fn get_res_name(&self) -> &str { + self.res_name.as_ref() + } + + pub fn get_resource_type(&self) -> ResourceType { + self.resource_type + } } impl MetricItemRetriever for ResourceNode {