github.com/ilhicas/nomad@v0.11.8/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  }