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

fix: Support kubelets using systemd cgroup driver #146

Merged
merged 1 commit into from
Jun 29, 2022
Merged
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
36 changes: 22 additions & 14 deletions src/sensors/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl ProcessTracker {
pub fn new(max_records_per_process: u16) -> ProcessTracker {
let regex_cgroup_docker = Regex::new(r"^/docker/.*$").unwrap();
let regex_cgroup_kubernetes = Regex::new(r"^/kubepods.*$").unwrap();
let regex_cgroup_containerd = Regex::new("/system.slice/containerd.service").unwrap();
let regex_cgroup_containerd = Regex::new("/system.slice/containerd.service/.*$").unwrap();
bpetit marked this conversation as resolved.
Show resolved Hide resolved
ProcessTracker {
procs: vec![],
max_records_per_process,
Expand Down Expand Up @@ -165,6 +165,9 @@ impl ProcessTracker {
if container_id.ends_with(".scope") {
container_id = container_id.strip_suffix(".scope").unwrap().to_string();
}
if container_id.contains("cri-containerd") {
container_id = container_id.split(':').last().unwrap().to_string();
}
Ok(container_id)
}

Expand Down Expand Up @@ -225,12 +228,20 @@ impl ProcessTracker {
}
}
found = true;
} else if self.regex_cgroup_kubernetes.is_match(&cg.pathname) {
// kubernetes
description.insert(
String::from("container_scheduler"),
String::from("kubernetes"),
);
} else {
// containerd
if self.regex_cgroup_containerd.is_match(&cg.pathname) {
description.insert(
String::from("container_runtime"),
String::from("containerd"),
);
} else if self.regex_cgroup_kubernetes.is_match(&cg.pathname) {
// kubernetes not using containerd but we can get the container id
} else {
// cgroup not related to a container technology
continue;
}

let container_id =
match self.extract_pod_id_from_cgroup_path(cg.pathname.clone()) {
Ok(id) => id,
Expand Down Expand Up @@ -273,6 +284,10 @@ impl ProcessTracker {
}
None => false,
}) {
description.insert(
String::from("container_scheduler"),
String::from("kubernetes"),
);
if let Some(pod_name) = &pod.metadata.name {
description
.insert(String::from("kubernetes_pod_name"), pod_name.clone());
Expand All @@ -293,13 +308,6 @@ impl ProcessTracker {
}
}
found = true;
} else if self.regex_cgroup_containerd.is_match(&cg.pathname) {
// containerd
description.insert(
String::from("container_runtime"),
String::from("containerd"),
);
found = true;
} //else {
// debug!("Cgroup not identified as related to a container technology : {}", &cg.pathname);
//}
Expand Down