Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add actual process name to attributes - refs #367 #368

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/exporters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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));

Expand Down
18 changes: 18 additions & 0 deletions src/sensors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
//CPU (all of them) time usage, as a percentage
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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<String> {
let mut result = self
Expand Down