Skip to content

Commit

Permalink
fix(host_metrics source): cgroups2 memeory metrics from root
Browse files Browse the repository at this point in the history
* cgroup_memory_anon_bytes and cgroup_memory_file_bytes are no longer
  zero on cgroups v2 systems
* test sources::host_metrics::cgroups::tests::generates_cgroups_metrics
  should no longer flap

I'm not sure why the is_root check was there for cgroups v2. Memory is
only in the root cgroup dir. No child dirs exist in cgroup root on my machine.
  • Loading branch information
bwerthmann committed Apr 12, 2024
1 parent 153919d commit e8e97ee
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/sources/host_metrics/cgroups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<'a> CGroupRecurser<'a> {
if self.load_cpu {
self.load_cpu(&cgroup, &tags).await;
}
if self.load_memory && !cgroup.is_root() {
if self.load_memory {
self.load_memory(&cgroup, &tags).await;
}

Expand Down Expand Up @@ -271,10 +271,6 @@ struct CGroup {
}

impl CGroup {
fn is_root(&self) -> bool {
self.name == Path::new("/")
}

fn tags(&self) -> MetricTags {
metric_tags! {
"cgroup" => self.name.to_string_lossy(),
Expand Down Expand Up @@ -599,11 +595,11 @@ mod tests {
);
assert_eq!(
count_name(&metrics, "cgroup_memory_anon_bytes"),
SUBDIRS.len() - 1
SUBDIRS.len()
);
assert_eq!(
count_name(&metrics, "cgroup_memory_file_bytes"),
SUBDIRS.len() - 1
SUBDIRS.len()
);
}

Expand Down

0 comments on commit e8e97ee

Please sign in to comment.