Skip to content

Commit

Permalink
Add swap statistics to CRI-API
Browse files Browse the repository at this point in the history
Signed-off-by: Itamar Holder <iholder@redhat.com>
  • Loading branch information
iholder101 committed Jul 17, 2023
1 parent 053d7ac commit 87ff9c4
Show file tree
Hide file tree
Showing 3 changed files with 823 additions and 442 deletions.
14 changes: 14 additions & 0 deletions pkg/kubelet/stats/cri_stats_provider.go
Expand Up @@ -577,6 +577,7 @@ func (p *criStatsProvider) makeContainerStats(
CPU: &statsapi.CPUStats{},
Memory: &statsapi.MemoryStats{},
Rootfs: &statsapi.FsStats{},
Swap: &statsapi.SwapStats{},
// UserDefinedMetrics is not supported by CRI.
}
if stats.Cpu != nil {
Expand Down Expand Up @@ -607,6 +608,19 @@ func (p *criStatsProvider) makeContainerStats(
result.Memory.Time = metav1.NewTime(time.Unix(0, time.Now().UnixNano()))
result.Memory.WorkingSetBytes = uint64Ptr(0)
}
if stats.Swap != nil {
result.Swap.Time = metav1.NewTime(time.Unix(0, stats.Swap.Timestamp))
if stats.Swap.SwapUsageBytes != nil {
result.Swap.SwapUsageBytes = &stats.Swap.SwapUsageBytes.Value
}
if stats.Swap.SwapAvailableBytes != nil {
result.Swap.SwapAvailableBytes = &stats.Swap.SwapAvailableBytes.Value
}
} else {
result.Swap.Time = metav1.NewTime(time.Unix(0, time.Now().UnixNano()))
result.Swap.SwapUsageBytes = uint64Ptr(0)
result.Swap.SwapAvailableBytes = uint64Ptr(0)
}
if stats.WritableLayer != nil {
result.Rootfs.Time = metav1.NewTime(time.Unix(0, stats.WritableLayer.Timestamp))
if stats.WritableLayer.UsedBytes != nil {
Expand Down

0 comments on commit 87ff9c4

Please sign in to comment.