diff --git a/noxis-rs/src/utils/metrics.rs b/noxis-rs/src/utils/metrics.rs index 07c77d8..c066dd5 100644 --- a/noxis-rs/src/utils/metrics.rs +++ b/noxis-rs/src/utils/metrics.rs @@ -5,6 +5,7 @@ use crate::{ options::structs::ProcessState, utils::metrics::processes::{ProcessesGeneral, ProcessesQuery}, }; +use chrono::Datelike; use log::warn; use noxis_cli::metrics_models::MetricsMode; use std::{any::Any, collections::BTreeMap, sync::Arc}; @@ -496,6 +497,8 @@ pub struct ProcessExtended { name: String, status: ProcessState, pid: Pid, + start_time: String, + duration: String, dependencies: processes::deps::Dependencies, cpu_usage: f32, ram_usage: u64, @@ -509,10 +512,31 @@ impl ProcessExtended { system.refresh_processes(sysinfo::ProcessesToUpdate::All, true); return if let Some(prc) = system.process(proc.pid.new_sysinfo_pid()) { let disk_usage = prc.disk_usage(); + let duration = chrono::Duration::new(prc.run_time() as i64, 0); + let start_time = chrono::DateTime::from_timestamp(prc.start_time() as i64, 0); Self { name: proc.name, status: proc.state, pid: proc.pid, + start_time : { + match start_time { + Some(date) => date.to_string(), + None => String::new() + } + }, + duration: { + match duration { + Some(duration) => { + format!("{}:{}:{}:{}", + duration.num_days(), + duration.num_hours(), + duration.num_minutes(), + duration.num_seconds() + ) + }, + None => String::new() + } + }, dependencies: proc.dependencies, cpu_usage: prc.cpu_usage(), ram_usage: prc.memory(), @@ -525,6 +549,8 @@ impl ProcessExtended { name: proc.name, status: proc.state, pid: proc.pid, + start_time : String::new(), + duration: String::new(), dependencies: proc.dependencies, cpu_usage: 0.0, ram_usage: 0,