From 009d659f74e9ec05d80346d594e9bb56a19652c7 Mon Sep 17 00:00:00 2001 From: Ross Fairbanks Date: Thu, 8 Jun 2023 14:45:38 +0200 Subject: [PATCH 1/2] fix: Kubernetes integration when using cgroups v2 --- src/sensors/utils.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sensors/utils.rs b/src/sensors/utils.rs index 1827d054..c3306a50 100644 --- a/src/sensors/utils.rs +++ b/src/sensors/utils.rs @@ -246,7 +246,7 @@ impl ProcessTracker { #[cfg(feature = "containers")] let regex_cgroup_docker = Regex::new(r"^.*/docker.*$").unwrap(); #[cfg(feature = "containers")] - let regex_cgroup_kubernetes = Regex::new(r"^/kubepods.*$").unwrap(); + let regex_cgroup_kubernetes = Regex::new(r"/kubepods.*$").unwrap(); #[cfg(feature = "containers")] let regex_cgroup_containerd = Regex::new("/system.slice/containerd.service/.*$").unwrap(); @@ -429,6 +429,9 @@ impl ProcessTracker { if container_id.contains("cri-containerd") { container_id = container_id.split(':').last().unwrap().to_string(); } + if container_id.starts_with("cri-containerd-") { + container_id = container_id.strip_prefix("cri-containerd-").unwrap().to_string(); + } Ok(container_id) } From 47ed17bc1402e9a500121fe7ba44903f5b2a5fd9 Mon Sep 17 00:00:00 2001 From: Ross Fairbanks Date: Thu, 8 Jun 2023 15:21:11 +0200 Subject: [PATCH 2/2] fix formatting --- src/sensors/utils.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sensors/utils.rs b/src/sensors/utils.rs index c3306a50..737c49ea 100644 --- a/src/sensors/utils.rs +++ b/src/sensors/utils.rs @@ -430,7 +430,10 @@ impl ProcessTracker { container_id = container_id.split(':').last().unwrap().to_string(); } if container_id.starts_with("cri-containerd-") { - container_id = container_id.strip_prefix("cri-containerd-").unwrap().to_string(); + container_id = container_id + .strip_prefix("cri-containerd-") + .unwrap() + .to_string(); } Ok(container_id) }