github.com/hernad/nomad@v1.6.112/drivers/docker/util/util.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package util
     5  
     6  func CalculateCPUPercent(newSample, oldSample, newTotal, oldTotal uint64, cores int) float64 {
     7  	numerator := newSample - oldSample
     8  	denom := newTotal - oldTotal
     9  	if numerator <= 0 || denom <= 0 {
    10  		return 0.0
    11  	}
    12  
    13  	return (float64(numerator) / float64(denom)) * float64(cores) * 100.0
    14  }