k8s.io/kubernetes@v1.29.3/pkg/kubelet/server/stats/summary_sys_containers_windows.go (about) 1 //go:build windows 2 // +build windows 3 4 /* 5 Copyright 2018 The Kubernetes Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 */ 19 20 package stats 21 22 import ( 23 "time" 24 25 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 statsapi "k8s.io/kubelet/pkg/apis/stats/v1alpha1" 27 "k8s.io/kubernetes/pkg/kubelet/cm" 28 ) 29 30 func (sp *summaryProviderImpl) GetSystemContainersStats(nodeConfig cm.NodeConfig, podStats []statsapi.PodStats, updateStats bool) (stats []statsapi.ContainerStats) { 31 stats = append(stats, sp.getSystemPodsCPUAndMemoryStats(nodeConfig, podStats, updateStats)) 32 return stats 33 } 34 35 func (sp *summaryProviderImpl) GetSystemContainersCPUAndMemoryStats(nodeConfig cm.NodeConfig, podStats []statsapi.PodStats, updateStats bool) (stats []statsapi.ContainerStats) { 36 stats = append(stats, sp.getSystemPodsCPUAndMemoryStats(nodeConfig, podStats, updateStats)) 37 return stats 38 } 39 40 func (sp *summaryProviderImpl) getSystemPodsCPUAndMemoryStats(nodeConfig cm.NodeConfig, podStats []statsapi.PodStats, updateStats bool) statsapi.ContainerStats { 41 now := metav1.NewTime(time.Now()) 42 podsSummary := statsapi.ContainerStats{ 43 StartTime: now, 44 CPU: &statsapi.CPUStats{}, 45 Memory: &statsapi.MemoryStats{}, 46 Name: statsapi.SystemContainerPods, 47 } 48 49 // Sum up all pod's stats. 50 var usageCoreNanoSeconds uint64 51 var usageNanoCores uint64 52 var availableBytes uint64 53 var usageBytes uint64 54 var workingSetBytes uint64 55 for _, pod := range podStats { 56 if pod.CPU != nil { 57 podsSummary.CPU.Time = now 58 if pod.CPU.UsageCoreNanoSeconds != nil { 59 usageCoreNanoSeconds = usageCoreNanoSeconds + *pod.CPU.UsageCoreNanoSeconds 60 } 61 if pod.CPU.UsageNanoCores != nil { 62 usageNanoCores = usageNanoCores + *pod.CPU.UsageNanoCores 63 } 64 } 65 66 if pod.Memory != nil { 67 podsSummary.Memory.Time = now 68 if pod.Memory.AvailableBytes != nil { 69 availableBytes = availableBytes + *pod.Memory.AvailableBytes 70 } 71 if pod.Memory.UsageBytes != nil { 72 usageBytes = usageBytes + *pod.Memory.UsageBytes 73 } 74 if pod.Memory.WorkingSetBytes != nil { 75 workingSetBytes = workingSetBytes + *pod.Memory.WorkingSetBytes 76 } 77 } 78 } 79 80 // Set results only if they are not zero. 81 if usageCoreNanoSeconds != 0 { 82 podsSummary.CPU.UsageCoreNanoSeconds = &usageCoreNanoSeconds 83 } 84 if usageNanoCores != 0 { 85 podsSummary.CPU.UsageNanoCores = &usageNanoCores 86 } 87 if availableBytes != 0 { 88 podsSummary.Memory.AvailableBytes = &availableBytes 89 } 90 if usageBytes != 0 { 91 podsSummary.Memory.UsageBytes = &usageBytes 92 } 93 if workingSetBytes != 0 { 94 podsSummary.Memory.WorkingSetBytes = &workingSetBytes 95 } 96 97 return podsSummary 98 }