Skip to content

Commit

Permalink
Re-introduce per-process CPU collection (#1146)
Browse files Browse the repository at this point in the history
### What does this PR do?

This commit re-introduces per-process CPU data from /proc/{pid}/stat reusing the
same naming scheme from the cgroup sourced data, offset with stat. to avoid
summing issues in aggregations.

I have removed much of the stat code from the main procfs sample loop. The data
was either no longer used or is duplicated elsewhere. Some data could be
re-introduced if we desire by extending the poll loop in stat.rs.

I am continuing to remove more and more of our procfs crate integration. I
think, ultimately, we should be able to parse directly without the need of a
third-party dependency. That removal is near done now.
  • Loading branch information
blt authored Dec 14, 2024
1 parent 4344486 commit 9f09b9a
Show file tree
Hide file tree
Showing 5 changed files with 524 additions and 262 deletions.
2 changes: 1 addition & 1 deletion lading/src/observer/linux/cgroup.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Code to read cgroup information.
mod v2;
pub(crate) mod v2;

use std::{collections::VecDeque, io};

Expand Down
5 changes: 4 additions & 1 deletion lading/src/observer/linux/cgroup/v2/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ pub(crate) async fn poll(group_prefix: &Path, labels: &[(String, String)]) -> Re
let user_fraction = delta_user as f64 / delta_time;
let system_fraction = delta_system as f64 / delta_time;

// NOTE these metric names are paired with names in procfs/stat.rs and
// must remain consistent. If you change these, change those.

// Convert usage to a percentage of the cores granted to the target.
let total_cpu = (usage_fraction / allowed_cores) * 100.0;
let user_cpu = (user_fraction / allowed_cores) * 100.0;
Expand All @@ -106,7 +109,7 @@ pub(crate) async fn poll(group_prefix: &Path, labels: &[(String, String)]) -> Re
gauge!("kernel_cpu_percentage", labels).set(system_cpu); // kernel is a misnomer, keeping for compatibility
gauge!("system_cpu_percentage", labels).set(system_cpu);

// Convert usage to kubernetes style millicores. These
// Convert usage to kubernetes style millicores.
let total_millicores = usage_fraction * 1000.0;
let user_millicores = user_fraction * 1000.0;
let system_millicores = system_fraction * 1000.0;
Expand Down
Loading

0 comments on commit 9f09b9a

Please sign in to comment.