-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Podman Stats additional features #10696
Conversation
cmd/podman/containers/stats.go
Outdated
@@ -146,7 +146,9 @@ func stats(cmd *cobra.Command, args []string) error { | |||
func outputStats(reports []define.ContainerStats) error { | |||
headers := report.Headers(define.ContainerStats{}, map[string]string{ | |||
"ID": "ID", | |||
"UpTime": "CPU TIME (S)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is UpTime really correect? I've always heard that as the total duration a system has been running for, not cumulative CPU time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the result of podman stats
ID NAME CPU TIME (S) CPU % AVG CPU % MEM USAGE / LIMIT MEM % NET IO BLOCK IO PIDS
f10ae061aa6b thirsty_colden 14m1.261643561s 1.28% 6.60% 729.4MB / 16.02GB 4.55% -- / -- -- / -- 117
I made it so that the CPU time pulls the container creation time if the variable is time's zero value. I assumed that CPU time just basically meant up time of the container? If I was wrong I can go back and adjust accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, CPU time is the number of seconds or CPU time the container has actively used, not seconds it has been alive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mheon I think most recent commit fixed this. I didn't realize cgroupStats.CPU.Usage.Total was a duration in ns of how much up time the group had. I switched around some things with avg CPU % given this information as well.
2e63a56
to
a45ae91
Compare
libpod/stats.go
Outdated
stats.CPU = calculateCPUPercent(cgroupStats, previousCPU, now, previousStats.SystemNano) | ||
stats.AvgCPU = calculateAvgCPU(stats.CPU, previousStats.CPUTrack) | ||
stats.CPUTrack = append(previousStats.CPUTrack, float64(cgroupStats.CPU.Usage.Total)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any risk that this can grow indefinitely or use outdated info (or should the average computed using all the available data points)?
If we need all data points, could we just store the current average and number of data points to calculate the incremental average?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, i will store number of datapoints and the current average I am pretty sure I can do ((oldAvg * numDataPoints) + newData) / (numDataPoints + 1)
e2bee36
to
6878875
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
libpod/stats.go
Outdated
|
||
// calculateAvgCPU calculates the avg CPU percentage given the previous average and the number of data points. | ||
func calculateAvgCPU(statsCPU float64, prevAvg float64, prevData int64) float64 { | ||
total := prevAvg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add a temporary variable? Why not just use prevAvg?
Expect(session.ExitCode()).To(Equal(0)) | ||
session = podmanTest.Podman([]string{"stats", "--all", "--no-stream", "--format", "\"{{.ID}} {{.UpTime}} {{.AVGCPU}}\""}) | ||
session.WaitWithDefaultTimeout() | ||
Expect(session.ExitCode()).To(Equal(0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you look for the header in the the output?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rhatdan do you mean something like
session = podmanTest.Podman([]string{"stats", "--all", "--no-stream", "--format", "\"{{.ID}} {{.UpTime}} {{.AVGCPU}}\""})
out := session.OutputToStringArray()
Expect(len(out)).To(BeNumerically("==", 3))
or would that not work? It seems that none of the stats tests actually validate the output too much.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No I just want you to make sure the headings you expect show up in the output.
Expect(session.LineInOutputContains("UpTime").To(BeTrue())
Expect(session.LineInOutputContains("AVGCPU").To(BeTrue())
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cdoern, giuseppe, rhatdan The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
cmd/podman/containers/stats.go
Outdated
@@ -166,7 +168,7 @@ func outputStats(reports []define.ContainerStats) error { | |||
if report.IsJSON(statsOptions.Format) { | |||
return outputJSON(stats) | |||
} | |||
format := "{{.ID}}\t{{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDS}}\n" | |||
format := "{{.ID}}\t{{.Name}}\t{{.UpTime}}\t{{.CPUPerc}}\t{{.AVGCPU}}\t{{.MemUsage}}\t{{.MemPerc}}\t{{.NetIO}}\t{{.BlockIO}}\t{{.PIDS}}\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I would classify this as a breaking change to compat, but it would probbaly be best if we added the new fields to the end of the output, that way, if someone built a script for docker that expected the second field to be CPUPerc, we would not break it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to switch around the ordering? I feel like that would make the output look strange though to have CPU data all scattered throughout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, I think we need to @cdoern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add an --alpha
flag which would then show the stats in alphabetical order left to right? Or if you really want to go off the rails, make it all selectable by the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomSweeneyRedHat working on an alpha flag right now, should it simply just be an if/else around format:=...
with two different options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomSweeneyRedHat I don't see the value for an extra alpha flag, the user can always change the output format with --format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tend to agree - I don't see a strong case for this until and unless we get a user request to add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so we are not going to move the new data to the end of stats? And just tell users if they want a specific format to use --format. I guess I am good with this. Make the default look good for the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Luap99 The value in my eye is just typing --alpha
rather than working it out in the --format
option. YMMV. I think it would be a good addition, but not a biggy.
82c21c3
to
79a7aa6
Compare
cmd/podman/containers/stats.go
Outdated
@@ -75,6 +76,7 @@ func statFlags(cmd *cobra.Command) { | |||
|
|||
flags.BoolVar(&statsOptions.NoReset, "no-reset", false, "Disable resetting the screen between intervals") | |||
flags.BoolVar(&statsOptions.NoStream, "no-stream", false, "Disable streaming stats and only pull the first result, default setting is false") | |||
flags.BoolVar(&statsOptions.Alpha, "alpha", false, "Decides whether or not to alphabetize the output") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we decided to not add the --alpha flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, sorry. Just removed it.
lgtm |
added Avg Cpu calculation and CPU up time to podman stats. Adding different feature sets in different PRs, CPU first. resolves containers#9258 Signed-off-by: cdoern <[email protected]>
/lgtm |
/hold cancel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've patched this on top of podman-3.2.2
, and I'm always getting exactly the same value for .CPUPerc
and the new .AVGCPU
at all times - is this expected to be fully hooked-up at this point (or dependent on another patch on top of 3.2.2
to function), or have I missed something?
(Also, if the manpages/docs aren't auto-generated from the code, could a doc update for these additions please also be added?)
@srcshelton running now and I can't seem to recreate this. Can I see how you're running this/your output? |
I've realised that this is likely because I'm running I'd suggest that the '{{.AVGCPU}}' option must gather data persistently beyond the |
Added Avg CPU calculation and CPU up time to podman stats. Adding different feature sets in different PRs, CPU first.
The CPU track array is used to keep track of all CPU usage values to tally up. AvgCPU contains the average CPU percent usage which is calculated using cgroupStats.CPU.Usage.Total. Lastly, the Start and UpTime stats keep track of when the CPU tracking was started and how long the CPU has been active for since that tracking began.
resolves #9258
Signed-off-by: cdoern [email protected]