github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/drivers/docker/util/util.go (about) 1 package util 2 3 func CalculateCPUPercent(newSample, oldSample, newTotal, oldTotal uint64, cores int) float64 { 4 numerator := newSample - oldSample 5 denom := newTotal - oldTotal 6 if numerator <= 0 || denom <= 0 { 7 return 0.0 8 } 9 10 return (float64(numerator) / float64(denom)) * float64(cores) * 100.0 11 }