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

Add support for displaying windows pod stats #1057

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions cmd/crictl/pod_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,33 +210,57 @@ func displayPodStats(
}
id := getTruncatedID(s.Attributes.Id, "")

linux := s.GetLinux()
var cpu, mem uint64
var ts int64

linux := s.GetLinux()
windows := s.GetWindows()

if linux != nil && windows != nil {
return fmt.Errorf("pod %q has both linux and windows stats which is not supported", id)
}

if linux != nil {
cpu = linux.GetCpu().GetUsageCoreNanoSeconds().GetValue()
mem = linux.GetMemory().GetWorkingSetBytes().GetValue()
ts = linux.GetCpu().GetTimestamp()
} else if windows != nil {
cpu = windows.GetCpu().GetUsageCoreNanoSeconds().GetValue()
mem = windows.GetMemory().GetWorkingSetBytes().GetValue()
ts = windows.GetCpu().GetTimestamp()
}

if cpu == 0 && mem == 0 {
// Skip without data, maybe windows pod
continue
}

var oldCpu uint64
var oldCpuTs int64
old, ok := oldStats[s.Attributes.Id]
if !ok {
// Skip new pod
continue
}

oldLinux := old.GetLinux()
oldWindows := old.GetWindows()
if linux != nil {
oldCpuTs = oldLinux.GetCpu().GetTimestamp()
oldCpu = oldLinux.GetCpu().GetUsageCoreNanoSeconds().GetValue()
} else if windows != nil {
oldCpuTs = oldWindows.GetCpu().GetTimestamp()
oldCpu = oldWindows.GetCpu().GetUsageCoreNanoSeconds().GetValue()
}

var cpuPerc float64
if cpu != 0 {
// Only generate cpuPerc for running sandbox
duration := linux.GetCpu().GetTimestamp() - oldLinux.GetCpu().GetTimestamp()
duration := ts - oldCpuTs
if duration == 0 {
return errors.New("cpu stat is not updated during sample")
}
cpuPerc = float64(cpu-oldLinux.GetCpu().GetUsageCoreNanoSeconds().GetValue()) / float64(duration) * 100
cpuPerc = float64(cpu-oldCpu) / float64(duration) * 100
}
display.AddRow([]string{
s.Attributes.GetMetadata().GetName(),
Expand Down