diff --git a/src/exporters/mod.rs b/src/exporters/mod.rs index 5b3d750c..13896fc4 100644 --- a/src/exporters/mod.rs +++ b/src/exporters/mod.rs @@ -926,10 +926,11 @@ impl MetricGenerator { for pid in self.topology.proc_tracker.get_alive_pids() { let exe = self.topology.proc_tracker.get_process_name(pid); + let name = self.topology.proc_tracker.get_process_os_name(pid); let cmdline = self.topology.proc_tracker.get_process_cmdline(pid); let mut attributes = HashMap::new(); - debug!("Working on {}: {}", pid, exe); + debug!("Working on {}: {}", pid, name); #[cfg(feature = "containers")] if self.watch_containers && (!self.containers.is_empty() || !self.pods.is_empty()) { @@ -955,6 +956,8 @@ impl MetricGenerator { attributes.insert("exe".to_string(), exe.clone()); + attributes.insert("name".to_string(), name.clone()); + if let Some(cmdline_str) = cmdline { attributes.insert("cmdline".to_string(), utils::filter_cmdline(&cmdline_str)); diff --git a/src/sensors/utils.rs b/src/sensors/utils.rs index 2ba070ab..17506744 100644 --- a/src/sensors/utils.rs +++ b/src/sensors/utils.rs @@ -69,6 +69,7 @@ pub struct IStatus { pub struct IProcess { pub pid: Pid, pub owner: u32, + pub name: String, pub comm: String, pub cmdline: Vec, //CPU (all of them) time usage, as a percentage @@ -109,6 +110,7 @@ impl IProcess { IProcess { pid: process.pid(), owner: 0, + name: process.name().to_string(), comm: String::from(process.exe().to_str().unwrap()), cmdline: process.cmd().to_vec(), cpu_usage_percentage: process.cpu_usage(), @@ -127,6 +129,7 @@ impl IProcess { IProcess { pid: process.pid(), owner: 0, + name: process.name().to_string(), comm: String::from(process.exe().to_str().unwrap()), cmdline: process.cmd().to_vec(), cpu_usage_percentage: process.cpu_usage(), @@ -637,6 +640,21 @@ impl ProcessTracker { process.first().unwrap().process.comm.clone() } + /// Returns the OS process name associated to a PID + pub fn get_process_os_name(&self, pid: Pid) -> String { + let mut result = self + .procs + .iter() + .filter(|x| !x.is_empty() && x.first().unwrap().process.pid == pid); + let process = result.next().unwrap(); + if result.next().is_some() { + panic!("Found two vectors of processes with the same id, maintainers should fix this."); + } + + debug!("End of get process os name."); + process.first().unwrap().process.name.clone() + } + /// Returns the cmdline string associated to a PID pub fn get_process_cmdline(&self, pid: Pid) -> Option { let mut result = self