mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
Add SwapStats to summary API through cadvisor
Signed-off-by: Itamar Holder <iholder@redhat.com>
This commit is contained in:
parent
a05d200ac8
commit
c74ee8045d
@ -152,6 +152,7 @@ func (p *cadvisorStatsProvider) ListPodStats(_ context.Context) ([]statsapi.PodS
|
|||||||
cpu, memory := cadvisorInfoToCPUandMemoryStats(podInfo)
|
cpu, memory := cadvisorInfoToCPUandMemoryStats(podInfo)
|
||||||
podStats.CPU = cpu
|
podStats.CPU = cpu
|
||||||
podStats.Memory = memory
|
podStats.Memory = memory
|
||||||
|
podStats.Swap = cadvisorInfoToSwapStats(podInfo)
|
||||||
podStats.ProcessStats = cadvisorInfoToProcessStats(podInfo)
|
podStats.ProcessStats = cadvisorInfoToProcessStats(podInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,6 +228,7 @@ func (p *cadvisorStatsProvider) ListPodCPUAndMemoryStats(_ context.Context) ([]s
|
|||||||
cpu, memory := cadvisorInfoToCPUandMemoryStats(podInfo)
|
cpu, memory := cadvisorInfoToCPUandMemoryStats(podInfo)
|
||||||
podStats.CPU = cpu
|
podStats.CPU = cpu
|
||||||
podStats.Memory = memory
|
podStats.Memory = memory
|
||||||
|
podStats.Swap = cadvisorInfoToSwapStats(podInfo)
|
||||||
}
|
}
|
||||||
result = append(result, *podStats)
|
result = append(result, *podStats)
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,7 @@ func cadvisorInfoToContainerStats(name string, info *cadvisorapiv2.ContainerInfo
|
|||||||
cpu, memory := cadvisorInfoToCPUandMemoryStats(info)
|
cpu, memory := cadvisorInfoToCPUandMemoryStats(info)
|
||||||
result.CPU = cpu
|
result.CPU = cpu
|
||||||
result.Memory = memory
|
result.Memory = memory
|
||||||
|
result.Swap = cadvisorInfoToSwapStats(info)
|
||||||
|
|
||||||
// NOTE: if they can be found, log stats will be overwritten
|
// NOTE: if they can be found, log stats will be overwritten
|
||||||
// by the caller, as it knows more information about the pod,
|
// by the caller, as it knows more information about the pod,
|
||||||
@ -257,6 +258,29 @@ func cadvisorInfoToUserDefinedMetrics(info *cadvisorapiv2.ContainerInfo) []stats
|
|||||||
return udm
|
return udm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cadvisorInfoToSwapStats(info *cadvisorapiv2.ContainerInfo) *statsapi.SwapStats {
|
||||||
|
cstat, found := latestContainerStats(info)
|
||||||
|
if !found {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var swapStats *statsapi.SwapStats
|
||||||
|
|
||||||
|
if info.Spec.HasMemory && cstat.Memory != nil {
|
||||||
|
swapStats = &statsapi.SwapStats{
|
||||||
|
Time: metav1.NewTime(cstat.Timestamp),
|
||||||
|
SwapUsageBytes: &cstat.Memory.Swap,
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isMemoryUnlimited(info.Spec.Memory.SwapLimit) {
|
||||||
|
swapAvailableBytes := info.Spec.Memory.SwapLimit - cstat.Memory.Swap
|
||||||
|
swapStats.SwapAvailableBytes = &swapAvailableBytes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return swapStats
|
||||||
|
}
|
||||||
|
|
||||||
// latestContainerStats returns the latest container stats from cadvisor, or nil if none exist
|
// latestContainerStats returns the latest container stats from cadvisor, or nil if none exist
|
||||||
func latestContainerStats(info *cadvisorapiv2.ContainerInfo) (*cadvisorapiv2.ContainerStats, bool) {
|
func latestContainerStats(info *cadvisorapiv2.ContainerInfo) (*cadvisorapiv2.ContainerStats, bool) {
|
||||||
stats := info.Stats
|
stats := info.Stats
|
||||||
|
Loading…
Reference in New Issue
Block a user