mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-02-22 07:03:28 +00:00
Fix pod and container level swap metrics for CRI
This commit is contained in:
@@ -343,6 +343,7 @@ func (p *criStatsProvider) ListPodCPUAndMemoryStats(ctx context.Context) ([]stat
|
||||
// Fill available CPU and memory stats for full set of required pod stats
|
||||
cs := p.makeContainerCPUAndMemoryStats(stats, container)
|
||||
p.addPodCPUMemoryStats(ps, types.UID(podSandbox.Metadata.Uid), allInfos, cs)
|
||||
p.addSwapStats(ps, types.UID(podSandbox.Metadata.Uid), allInfos, cs)
|
||||
|
||||
// If cadvisor stats is available for the container, use it to populate
|
||||
// container stats
|
||||
@@ -743,6 +744,11 @@ func (p *criStatsProvider) makeContainerCPUAndMemoryStats(
|
||||
StartTime: metav1.NewTime(time.Unix(0, container.CreatedAt)),
|
||||
CPU: &statsapi.CPUStats{},
|
||||
Memory: &statsapi.MemoryStats{},
|
||||
Swap: &statsapi.SwapStats{
|
||||
Time: metav1.NewTime(time.Unix(0, time.Now().UnixNano())),
|
||||
SwapUsageBytes: uint64Ptr(0),
|
||||
SwapAvailableBytes: uint64Ptr(0),
|
||||
},
|
||||
// UserDefinedMetrics is not supported by CRI.
|
||||
}
|
||||
if stats.Cpu != nil {
|
||||
@@ -771,6 +777,15 @@ func (p *criStatsProvider) makeContainerCPUAndMemoryStats(
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -61,7 +61,8 @@ var _ = SIGDescribe("ResourceMetricsAPI", feature.ResourceMetrics, func() {
|
||||
|
||||
keys := []string{
|
||||
"resource_scrape_error", "node_cpu_usage_seconds_total", "node_memory_working_set_bytes",
|
||||
"pod_cpu_usage_seconds_total", "pod_memory_working_set_bytes",
|
||||
"pod_cpu_usage_seconds_total", "pod_memory_working_set_bytes", "node_swap_usage_bytes",
|
||||
"container_swap_usage_bytes", "pod_swap_usage_bytes",
|
||||
}
|
||||
|
||||
// NOTE: This check should be removed when ListMetricDescriptors is implemented
|
||||
|
||||
Reference in New Issue
Block a user