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

get docker container cpu usage from cpuacct.usage #581

Merged
merged 2 commits into from Sep 27, 2018

Conversation

Projects
None yet
2 participants
@CMGS
Contributor

CMGS commented Sep 11, 2018

This PR for:

  • Get cgroup cpu usage from cpuacct.usage, it's a nanoseconds data, so I trans it to seconds.
  • Make CgroupCPUWithContext return same unit like cpu.Times. I saw cpu.Times will trans jiffies to seconds, so here should divide CPUTick.

After this change, we can calculate container CPU percent in host view and container view like this:

interval := Seconds
containerCPUStat1 := CgroupCPUDocker(cid)
hostCPUStat1 := cpu.Times(false)[0]
time.sleep(interval)
hostCPUStat2 := cpu.Times(false)[0]
containerCPUStat2 := CgroupCPUDocker(cid)

percentInHostView := (containerCPUStat2.Usage - containerCPUStat1.Usage) / (hostCPUStat2.Total() - hostCPUStat1.Total())

percentInContainerView := percentInHostView * CPUNumbers
@shirou

This comment has been minimized.

Show comment
Hide comment
@shirou

shirou Sep 16, 2018

Owner

Thank you for your PR. but it seems this PR breaks compatibility about CgroupCPU. (*cpu.TimesStat -> CgroupCPUStat) We don't want to change API compatiblity, so it should be merge on v3.

or, because CgroupCPUUsage is just added and not break compatibility, we can merge it if you separate this PR.

Owner

shirou commented Sep 16, 2018

Thank you for your PR. but it seems this PR breaks compatibility about CgroupCPU. (*cpu.TimesStat -> CgroupCPUStat) We don't want to change API compatiblity, so it should be merge on v3.

or, because CgroupCPUUsage is just added and not break compatibility, we can merge it if you separate this PR.

@CMGS

This comment has been minimized.

Show comment
Hide comment
@CMGS

CMGS Sep 16, 2018

Contributor

@shirou So, could I add Usage into cpu.TimesStat? In this way, CgroupCPU can return *cpu.TimesStat

Contributor

CMGS commented Sep 16, 2018

@shirou So, could I add Usage into cpu.TimesStat? In this way, CgroupCPU can return *cpu.TimesStat

@shirou

This comment has been minimized.

Show comment
Hide comment
@shirou

shirou Sep 16, 2018

Owner

No. cpuacct is not same meaning in all platform. If you add only CgroupCPUUsage users who use cgroup can get usage without breaking. compatibility. No need to add usage to CgroupCPU, I think.

Owner

shirou commented Sep 16, 2018

No. cpuacct is not same meaning in all platform. If you add only CgroupCPUUsage users who use cgroup can get usage without breaking. compatibility. No need to add usage to CgroupCPU, I think.

@CMGS

This comment has been minimized.

Show comment
Hide comment
@CMGS

CMGS Sep 20, 2018

Contributor

OK, let me think about it...

Contributor

CMGS commented Sep 20, 2018

OK, let me think about it...

@CMGS

This comment has been minimized.

Show comment
Hide comment
@CMGS

CMGS Sep 21, 2018

Contributor

separate PR done

Contributor

CMGS commented Sep 21, 2018

separate PR done

@shirou

This comment has been minimized.

Show comment
Hide comment
@shirou

shirou Sep 27, 2018

Owner

Sorry for late response and thank you for your contribution!

Owner

shirou commented Sep 27, 2018

Sorry for late response and thank you for your contribution!

@shirou shirou merged commit a11c78b into shirou:master Sep 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment