Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add stats function to task #217

Merged
merged 6 commits into from
Aug 4, 2023
Merged

feat: add stats function to task #217

merged 6 commits into from
Aug 4, 2023

Conversation

Mossaka
Copy link
Member

@Mossaka Mossaka commented Aug 1, 2023

This PR adds a new stats function to the implementation of a Task. It uses cgroups_rs crate to get the memory stats from cgroup subsystems, which is largely inspired by how containerd runc shim is implemented in rust-extensions repo.

This is currently work-in-process but I want to get it out there so to collect some early feedback.

If you want to test it, you can use ctr task metric <task-name> to print out the memory usage of the task

➜  runwasi git:(stats) ✗ sudo ctr task metric testwasm
ID          TIMESTAMP                              
testwasm    seconds:1690930464  nanos:407172844    

METRIC                   VALUE       
memory.usage_in_bytes    18649088    
memory.limit_in_bytes    0           
memory.stat.cache        0           
cpuacct.usage            3545445     
cpuacct.usage_percpu     []          
pids.current             9           
pids.limit               0     

TODO:

  • unit tests the stats function in cgroup v1
  • unit tests the stats function in cgroup v2

Closes #208

Signed-off-by: jiaxiao zhou <jiazho@microsoft.com>
Signed-off-by: jiaxiao zhou <jiazho@microsoft.com>
let mut metrics = Metrics::new();
let hier = hierarchies::auto();
let cgroup: Cgroup;
if hier.v2() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact, hier means "yesterday" in french :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😮

Signed-off-by: jiaxiao zhou <jiazho@microsoft.com>
This commits adds CPUAcct and Pid metircs to report to containerd

Signed-off-by: jiaxiao zhou <jiazho@microsoft.com>
Signed-off-by: jiaxiao zhou <jiazho@microsoft.com>
This commit uses the cpu controller to collect stats from the CPU
instead of the cpuacct controller.

Signed-off-by: jiaxiao zhou <jiazho@microsoft.com>
@Mossaka
Copy link
Member Author

Mossaka commented Aug 1, 2023

I am now able to get more metrics, including CPU and PIDs!!

➜  runwasi git:(stats) ✗ sudo ctr task metric testwasm
ID          TIMESTAMP                              
testwasm    seconds:1690930464  nanos:407172844    

METRIC                   VALUE       
memory.usage_in_bytes    18649088    
memory.limit_in_bytes    0           
memory.stat.cache        0           
cpuacct.usage            3545445     
cpuacct.usage_percpu     []          
pids.current             9           
pids.limit               0     

@Mossaka Mossaka requested a review from rumpl August 1, 2023 23:29
@Mossaka
Copy link
Member Author

Mossaka commented Aug 2, 2023

Just ran the ctr task metrics on ubuntu 20.04 machine with cgroup v1. Verified it works.

@jsturtevant
Copy link
Contributor

can we re-use the work you did in containerd/rust-extensions#163?

@Mossaka
Copy link
Member Author

Mossaka commented Aug 4, 2023

can we re-use the work you did in containerd/rust-extensions#163?

sure that's my intention

Copy link
Contributor

@devigned devigned left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

I'm super excited to start seeing metrics being produced.

@Mossaka
Copy link
Member Author

Mossaka commented Aug 4, 2023

Will merge this now

@Mossaka Mossaka merged commit 4992d3c into containerd:main Aug 4, 2023
7 checks passed
@Mossaka Mossaka deleted the stats branch August 4, 2023 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Stats() from Task trait
4 participants