(previousStats *ContainerStats, metrics *v1.Metrics, systemInfo SystemInfo)
| 115 | } |
| 116 | |
| 117 | func calculateCgroupCPUPercent(previousStats *ContainerStats, metrics *v1.Metrics, systemInfo SystemInfo) float64 { |
| 118 | var ( |
| 119 | cpuPercent = 0.0 |
| 120 | // calculate the change for the cpu usage of the container in between readings |
| 121 | cpuDelta = float64(metrics.CPU.Usage.Total) - float64(previousStats.CgroupCPU) |
| 122 | // calculate the change for the entire system between readings |
| 123 | systemDelta = float64(systemInfo.SystemUsage) - float64(previousStats.CgroupSystem) |
| 124 | onlineCPUs = systemInfo.OnlineCPUs |
| 125 | ) |
| 126 | |
| 127 | if onlineCPUs == 0 { |
| 128 | onlineCPUs = uint32(len(metrics.CPU.Usage.PerCPU)) |
| 129 | } |
| 130 | if systemDelta > 0.0 && cpuDelta > 0.0 { |
| 131 | cpuPercent = (cpuDelta / systemDelta) * float64(onlineCPUs) * 100.0 |
| 132 | } |
| 133 | return cpuPercent |
| 134 | } |
| 135 | |
| 136 | // PercpuUsage is not supported in CgroupV2 |
| 137 | func calculateCgroup2CPUPercent(previousStats *ContainerStats, metrics *v2.Metrics) float64 { |
no outgoing calls
no test coverage detected
searching dependent graphs…