summary_sys_containers_windows.go 3.0 KB

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