From d961b21beef47d15ba2903bc58ebcc92cc4c75ce Mon Sep 17 00:00:00 2001 From: nionata Date: Thu, 9 Jan 2025 12:27:36 -0800 Subject: [PATCH] feat(host_metrics source): Add additional cgroup memory metrics --- ..._inactive_cgroup_memory_metrics.feature.md | 3 ++ src/sources/host_metrics/cgroups.rs | 44 +++++++++++++++++++ .../components/sources/host_metrics.cue | 4 ++ 3 files changed, 51 insertions(+) create mode 100644 changelog.d/add_active_and_inactive_cgroup_memory_metrics.feature.md diff --git a/changelog.d/add_active_and_inactive_cgroup_memory_metrics.feature.md b/changelog.d/add_active_and_inactive_cgroup_memory_metrics.feature.md new file mode 100644 index 0000000000000..34d1abc88f192 --- /dev/null +++ b/changelog.d/add_active_and_inactive_cgroup_memory_metrics.feature.md @@ -0,0 +1,3 @@ +Add active and inactive metrics for anon and file memory to the cgroup collector. These additional metrics allow you to better understand the existing cgroup memory metrics. + +authors: nionata \ No newline at end of file diff --git a/src/sources/host_metrics/cgroups.rs b/src/sources/host_metrics/cgroups.rs index 5f999003f074f..97cc788efb3a0 100644 --- a/src/sources/host_metrics/cgroups.rs +++ b/src/sources/host_metrics/cgroups.rs @@ -177,6 +177,26 @@ impl<'a> CGroupRecurser<'a> { .gauge("cgroup_memory_anon_bytes", stat.anon as f64, tags.clone()); self.output .gauge("cgroup_memory_file_bytes", stat.file as f64, tags.clone()); + self.output.gauge( + "cgroup_memory_anon_active_bytes", + stat.active_anon as f64, + tags.clone(), + ); + self.output.gauge( + "cgroup_memory_anon_inactive_bytes", + stat.inactive_anon as f64, + tags.clone(), + ); + self.output.gauge( + "cgroup_memory_file_active_bytes", + stat.active_file as f64, + tags.clone(), + ); + self.output.gauge( + "cgroup_memory_file_inactive_bytes", + stat.inactive_file as f64, + tags.clone(), + ); } } } @@ -389,6 +409,10 @@ define_stat_struct! { MemoryStat( // for more details. anon, file, + active_anon, + inactive_anon, + active_file, + inactive_file, )} fn is_dir(path: impl AsRef) -> bool { @@ -469,6 +493,10 @@ mod tests { assert_ne!(count_name(&metrics, "cgroup_cpu_system_seconds_total"), 0); assert_ne!(count_name(&metrics, "cgroup_memory_anon_bytes"), 0); assert_ne!(count_name(&metrics, "cgroup_memory_file_bytes"), 0); + assert_ne!(count_name(&metrics, "cgroup_memory_anon_active_bytes"), 0); + assert_ne!(count_name(&metrics, "cgroup_memory_anon_inactive_bytes"), 0); + assert_ne!(count_name(&metrics, "cgroup_memory_file_active_bytes"), 0); + assert_ne!(count_name(&metrics, "cgroup_memory_file_inactive_bytes"), 0); } #[tokio::test] @@ -601,6 +629,22 @@ mod tests { count_name(&metrics, "cgroup_memory_file_bytes"), SUBDIRS.len() ); + assert_eq!( + count_name(&metrics, "cgroup_memory_anon_active_bytes"), + SUBDIRS.len() + ); + assert_eq!( + count_name(&metrics, "cgroup_memory_anon_inactive_bytes"), + SUBDIRS.len() + ); + assert_eq!( + count_name(&metrics, "cgroup_memory_file_active_bytes"), + SUBDIRS.len() + ); + assert_eq!( + count_name(&metrics, "cgroup_memory_file_inactive_bytes"), + SUBDIRS.len() + ); } fn group(&mut self, subdir: &str, flags: usize, controllers: Option<&str>) { diff --git a/website/cue/reference/components/sources/host_metrics.cue b/website/cue/reference/components/sources/host_metrics.cue index f2ba3adf8e93c..d8762352f9a2d 100644 --- a/website/cue/reference/components/sources/host_metrics.cue +++ b/website/cue/reference/components/sources/host_metrics.cue @@ -120,6 +120,10 @@ components: sources: host_metrics: { cgroup_memory_current_bytes: _host & _cgroup_memory & {description: "The total amount of memory currently being used by this cgroup and its descendants, in bytes."} cgroup_memory_anon_bytes: _host & _cgroup_memory & {description: "The total amount of memory used by this cgroup in anonymous mappings (normal program allocation), in bytes."} cgroup_memory_file_bytes: _host & _cgroup_memory & {description: "The total amount of memory used by this cgroup to cache filesystem data, including tmpfs and shared memory, in bytes."} + cgroup_memory_anon_active_bytes: _host & _cgroup_memory & {description: "Amount of memory, swap-backed, on the internal memory management active lists used by the page reclaim algorithm, in bytes."} + cgroup_memory_anon_inactive_bytes: _host & _cgroup_memory & {description: "Amount of memory, swap-backed, on the internal memory management inactive lists used by the page reclaim algorithm, in bytes."} + cgroup_memory_file_active_bytes: _host & _cgroup_memory & {description: "Amount of memory, filesystem-backed, on the internal memory management active lists used by the page reclaim algorithm, in bytes."} + cgroup_memory_file_inactive_bytes: _host & _cgroup_memory & {description: "Amount of memory, filesystem-backed, on the internal memory management inactive lists used by the page reclaim algorithm, in bytes."} // Host disk disk_read_bytes_total: _host & _disk_counter & {description: "The accumulated number of bytes read in."}