Skip to content

Commit

Permalink
feat(host_metrics source): Add additional cgroup memory metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
nionata committed Jan 10, 2025
1 parent 99af5be commit d961b21
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions src/sources/host_metrics/cgroups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}
}
}
Expand Down Expand Up @@ -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<Path>) -> bool {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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>) {
Expand Down
4 changes: 4 additions & 0 deletions website/cue/reference/components/sources/host_metrics.cue
Original file line number Diff line number Diff line change
Expand Up @@ -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."}
Expand Down

0 comments on commit d961b21

Please sign in to comment.