mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
kubelet: Move Linux stats to a Linux specific file
This commit moves the Linux stats from CRI to a linux specific file and adds unimplemented methods for platform other than Linux and Windows.
This commit is contained in:
parent
03ff890ef4
commit
14952cef5b
@ -247,15 +247,7 @@ func (p *criStatsProvider) listPodStatsStrictlyFromCRI(ctx context.Context, upda
|
||||
continue
|
||||
}
|
||||
ps := buildPodStats(podSandbox)
|
||||
for _, criContainerStat := range criSandboxStat.Linux.Containers {
|
||||
container, found := containerMap[criContainerStat.Attributes.Id]
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
// Fill available stats for full set of required pod stats
|
||||
cs := p.makeContainerStats(criContainerStat, container, rootFsInfo, fsIDtoInfo, podSandbox.GetMetadata(), updateCPUNanoCoreUsage)
|
||||
ps.Containers = append(ps.Containers, *cs)
|
||||
}
|
||||
p.addCRIPodContainerStats(criSandboxStat, ps, fsIDtoInfo, containerMap, podSandbox, rootFsInfo, updateCPUNanoCoreUsage)
|
||||
addCRIPodNetworkStats(ps, criSandboxStat)
|
||||
addCRIPodCPUStats(ps, criSandboxStat)
|
||||
addCRIPodMemoryStats(ps, criSandboxStat)
|
||||
@ -914,22 +906,6 @@ func extractIDFromCgroupPath(cgroupPath string) string {
|
||||
return id
|
||||
}
|
||||
|
||||
func addCRIPodNetworkStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
if criPodStat == nil || criPodStat.Linux == nil || criPodStat.Linux.Network == nil {
|
||||
return
|
||||
}
|
||||
criNetwork := criPodStat.Linux.Network
|
||||
iStats := statsapi.NetworkStats{
|
||||
Time: metav1.NewTime(time.Unix(0, criNetwork.Timestamp)),
|
||||
InterfaceStats: criInterfaceToSummary(criNetwork.DefaultInterface),
|
||||
Interfaces: make([]statsapi.InterfaceStats, 0, len(criNetwork.Interfaces)),
|
||||
}
|
||||
for _, iface := range criNetwork.Interfaces {
|
||||
iStats.Interfaces = append(iStats.Interfaces, criInterfaceToSummary(iface))
|
||||
}
|
||||
ps.Network = &iStats
|
||||
}
|
||||
|
||||
func criInterfaceToSummary(criIface *runtimeapi.NetworkInterfaceUsage) statsapi.InterfaceStats {
|
||||
return statsapi.InterfaceStats{
|
||||
Name: criIface.Name,
|
||||
@ -940,43 +916,6 @@ func criInterfaceToSummary(criIface *runtimeapi.NetworkInterfaceUsage) statsapi.
|
||||
}
|
||||
}
|
||||
|
||||
func addCRIPodCPUStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
if criPodStat == nil || criPodStat.Linux == nil || criPodStat.Linux.Cpu == nil {
|
||||
return
|
||||
}
|
||||
criCPU := criPodStat.Linux.Cpu
|
||||
ps.CPU = &statsapi.CPUStats{
|
||||
Time: metav1.NewTime(time.Unix(0, criCPU.Timestamp)),
|
||||
UsageNanoCores: valueOfUInt64Value(criCPU.UsageNanoCores),
|
||||
UsageCoreNanoSeconds: valueOfUInt64Value(criCPU.UsageCoreNanoSeconds),
|
||||
}
|
||||
}
|
||||
|
||||
func addCRIPodMemoryStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
if criPodStat == nil || criPodStat.Linux == nil || criPodStat.Linux.Memory == nil {
|
||||
return
|
||||
}
|
||||
criMemory := criPodStat.Linux.Memory
|
||||
ps.Memory = &statsapi.MemoryStats{
|
||||
Time: metav1.NewTime(time.Unix(0, criMemory.Timestamp)),
|
||||
AvailableBytes: valueOfUInt64Value(criMemory.AvailableBytes),
|
||||
UsageBytes: valueOfUInt64Value(criMemory.UsageBytes),
|
||||
WorkingSetBytes: valueOfUInt64Value(criMemory.WorkingSetBytes),
|
||||
RSSBytes: valueOfUInt64Value(criMemory.RssBytes),
|
||||
PageFaults: valueOfUInt64Value(criMemory.PageFaults),
|
||||
MajorPageFaults: valueOfUInt64Value(criMemory.MajorPageFaults),
|
||||
}
|
||||
}
|
||||
|
||||
func addCRIPodProcessStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
if criPodStat == nil || criPodStat.Linux == nil || criPodStat.Linux.Process == nil {
|
||||
return
|
||||
}
|
||||
ps.ProcessStats = &statsapi.ProcessStats{
|
||||
ProcessCount: valueOfUInt64Value(criPodStat.Linux.Process.ProcessCount),
|
||||
}
|
||||
}
|
||||
|
||||
func valueOfUInt64Value(value *runtimeapi.UInt64Value) *uint64 {
|
||||
if value == nil {
|
||||
return nil
|
||||
|
105
pkg/kubelet/stats/cri_stats_provider_linux.go
Normal file
105
pkg/kubelet/stats/cri_stats_provider_linux.go
Normal file
@ -0,0 +1,105 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
/*
|
||||
Copyright 2023 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package stats
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
|
||||
)
|
||||
|
||||
func (p *criStatsProvider) addCRIPodContainerStats(criSandboxStat *runtimeapi.PodSandboxStats,
|
||||
ps *statsapi.PodStats, fsIDtoInfo map[runtimeapi.FilesystemIdentifier]*cadvisorapiv2.FsInfo,
|
||||
containerMap map[string]*runtimeapi.Container,
|
||||
podSandbox *runtimeapi.PodSandbox,
|
||||
rootFsInfo *cadvisorapiv2.FsInfo, updateCPUNanoCoreUsage bool) {
|
||||
for _, criContainerStat := range criSandboxStat.Linux.Containers {
|
||||
container, found := containerMap[criContainerStat.Attributes.Id]
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
// Fill available stats for full set of required pod stats
|
||||
cs := p.makeContainerStats(criContainerStat, container, rootFsInfo, fsIDtoInfo, podSandbox.GetMetadata(),
|
||||
updateCPUNanoCoreUsage)
|
||||
ps.Containers = append(ps.Containers, *cs)
|
||||
}
|
||||
}
|
||||
|
||||
func addCRIPodNetworkStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
if criPodStat == nil || criPodStat.Linux == nil || criPodStat.Linux.Network == nil {
|
||||
return
|
||||
}
|
||||
criNetwork := criPodStat.Linux.Network
|
||||
iStats := statsapi.NetworkStats{
|
||||
Time: metav1.NewTime(time.Unix(0, criNetwork.Timestamp)),
|
||||
InterfaceStats: criInterfaceToSummary(criNetwork.DefaultInterface),
|
||||
Interfaces: make([]statsapi.InterfaceStats, 0, len(criNetwork.Interfaces)),
|
||||
}
|
||||
for _, iface := range criNetwork.Interfaces {
|
||||
iStats.Interfaces = append(iStats.Interfaces, criInterfaceToSummary(iface))
|
||||
}
|
||||
ps.Network = &iStats
|
||||
}
|
||||
|
||||
func addCRIPodMemoryStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
if criPodStat == nil || criPodStat.Linux == nil || criPodStat.Linux.Memory == nil {
|
||||
return
|
||||
}
|
||||
criMemory := criPodStat.Linux.Memory
|
||||
ps.Memory = &statsapi.MemoryStats{
|
||||
Time: metav1.NewTime(time.Unix(0, criMemory.Timestamp)),
|
||||
AvailableBytes: valueOfUInt64Value(criMemory.AvailableBytes),
|
||||
UsageBytes: valueOfUInt64Value(criMemory.UsageBytes),
|
||||
WorkingSetBytes: valueOfUInt64Value(criMemory.WorkingSetBytes),
|
||||
RSSBytes: valueOfUInt64Value(criMemory.RssBytes),
|
||||
PageFaults: valueOfUInt64Value(criMemory.PageFaults),
|
||||
MajorPageFaults: valueOfUInt64Value(criMemory.MajorPageFaults),
|
||||
}
|
||||
}
|
||||
|
||||
func addCRIPodCPUStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
if criPodStat == nil || criPodStat.Linux == nil || criPodStat.Linux.Cpu == nil {
|
||||
return
|
||||
}
|
||||
criCPU := criPodStat.Linux.Cpu
|
||||
ps.CPU = &statsapi.CPUStats{
|
||||
Time: metav1.NewTime(time.Unix(0, criCPU.Timestamp)),
|
||||
UsageNanoCores: valueOfUInt64Value(criCPU.UsageNanoCores),
|
||||
UsageCoreNanoSeconds: valueOfUInt64Value(criCPU.UsageCoreNanoSeconds),
|
||||
}
|
||||
}
|
||||
|
||||
func addCRIPodProcessStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
if criPodStat == nil || criPodStat.Linux == nil || criPodStat.Linux.Process == nil {
|
||||
return
|
||||
}
|
||||
ps.ProcessStats = &statsapi.ProcessStats{
|
||||
ProcessCount: valueOfUInt64Value(criPodStat.Linux.Process.ProcessCount),
|
||||
}
|
||||
}
|
||||
|
||||
// listContainerNetworkStats returns the network stats of all the running containers.
|
||||
// It should return (nil, nil) for platforms other than Windows.
|
||||
func (p *criStatsProvider) listContainerNetworkStats() (map[string]*statsapi.NetworkStats, error) {
|
||||
return nil, nil
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
//go:build !linux && !windows
|
||||
// +build !linux,!windows
|
||||
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
@ -20,6 +20,8 @@ limitations under the License.
|
||||
package stats
|
||||
|
||||
import (
|
||||
cadvisorapiv2 "github.com/google/cadvisor/info/v2"
|
||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1"
|
||||
)
|
||||
|
||||
@ -28,3 +30,22 @@ import (
|
||||
func (p *criStatsProvider) listContainerNetworkStats() (map[string]*statsapi.NetworkStats, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (p *criStatsProvider) addCRIPodContainerStats(criSandboxStat *runtimeapi.PodSandboxStats,
|
||||
ps *statsapi.PodStats, fsIDtoInfo map[runtimeapi.FilesystemIdentifier]*cadvisorapiv2.FsInfo,
|
||||
containerMap map[string]*runtimeapi.Container,
|
||||
podSandbox *runtimeapi.PodSandbox,
|
||||
rootFsInfo *cadvisorapiv2.FsInfo, updateCPUNanoCoreUsage bool) {
|
||||
}
|
||||
|
||||
func addCRIPodNetworkStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
}
|
||||
|
||||
func addCRIPodMemoryStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
}
|
||||
|
||||
func addCRIPodCPUStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
}
|
||||
|
||||
func addCRIPodProcessStats(ps *statsapi.PodStats, criPodStat *runtimeapi.PodSandboxStats) {
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user