diff --git a/agent/src/monitor.rs b/agent/src/monitor.rs index ac08f92cf41..999d67b4254 100644 --- a/agent/src/monitor.rs +++ b/agent/src/monitor.rs @@ -233,7 +233,7 @@ impl RefCountable for SysStatusBroker { CounterValue::Unsigned(self.config.load().sys_free_memory_limit as u64), )); - match get_file_and_size_sum(self.log_dir.clone()) { + match get_file_and_size_sum(&self.log_dir) { Ok(file_and_size_sum) => { metrics.push(( "log_file_size_sum", diff --git a/agent/src/trident.rs b/agent/src/trident.rs index f149553789f..a16e53fd321 100644 --- a/agent/src/trident.rs +++ b/agent/src/trident.rs @@ -968,7 +968,7 @@ pub struct DomainNameListener { } impl DomainNameListener { - const INTERVAL: u64 = 5; + const INTERVAL: Duration = Duration::from_secs(5); fn new( stats_collector: Arc, @@ -979,14 +979,11 @@ impl DomainNameListener { agent_id_tx: Arc>, ) -> DomainNameListener { Self { - stats_collector: stats_collector.clone(), + stats_collector, session, - - domain_names: domain_names.clone(), - ips: ips.clone(), - + domain_names, + ips, sidecar_mode, - thread_handler: None, stopped: Arc::new(AtomicBool::new(false)), agent_id_tx, @@ -1035,7 +1032,7 @@ impl DomainNameListener { .name("domain-name-listener".to_owned()) .spawn(move || { while !stopped.swap(false, Ordering::Relaxed) { - thread::sleep(Duration::from_secs(Self::INTERVAL)); + thread::sleep(Self::INTERVAL); let mut changed = false; for i in 0..domain_names.len() { diff --git a/agent/src/utils/guard.rs b/agent/src/utils/guard.rs index 32fa0e4ddae..c3f62d3d298 100644 --- a/agent/src/utils/guard.rs +++ b/agent/src/utils/guard.rs @@ -229,10 +229,10 @@ impl Guard { let config = config.load(); let tap_mode = config.tap_mode; let cpu_limit = config.max_cpus; - match get_file_and_size_sum(log_dir.clone()) { + match get_file_and_size_sum(&log_dir) { Ok(file_and_size_sum) => { let log_file_size = config.log_file_size; // Log file size limit (unit: M) - let file_sizes_sum = file_and_size_sum.file_sizes_sum.clone(); // Total size of current log files (unit: B) + let file_sizes_sum = file_and_size_sum.file_sizes_sum; // Total size of current log files (unit: B) debug!( "current log files' size: {}B, log_file_size_limit: {}B", file_sizes_sum, diff --git a/agent/src/utils/process/process.rs b/agent/src/utils/process/process.rs index 3eeef3660c3..e7e9c21474c 100644 --- a/agent/src/utils/process/process.rs +++ b/agent/src/utils/process/process.rs @@ -68,10 +68,10 @@ impl Ord for FileInfo { } /// 获取指定路径下的所有文件的信息及文件大小总和(单位:B) -pub fn get_file_and_size_sum(dir: String) -> io::Result { +pub fn get_file_and_size_sum(dir: &String) -> io::Result { let mut file_and_size_sum = FileAndSizeSum::new(); let mut file_infos = Vec::new(); - let dir = Path::new(dir.as_str()); + let dir = Path::new(dir); for item in fs::read_dir(dir)? { let file = match item { Ok(f) => f,