Fix usage of housekeeping_interval flag
Defer calculation of `loadDecay`. Flags must be parsed before they can be read, and therefore cannot be reliably be read at package init time.
This commit is contained in:
parent
0d6015c741
commit
33216870d8
@ -44,9 +44,6 @@ var HousekeepingInterval = flag.Duration("housekeeping_interval", 1*time.Second,
|
|||||||
|
|
||||||
var cgroupPathRegExp = regexp.MustCompile(".*devices.*:(.*?)[,;$].*")
|
var cgroupPathRegExp = regexp.MustCompile(".*devices.*:(.*?)[,;$].*")
|
||||||
|
|
||||||
// Decay value used for load average smoothing. Interval length of 10 seconds is used.
|
|
||||||
var loadDecay = math.Exp(float64(-1 * (*HousekeepingInterval).Seconds() / 10))
|
|
||||||
|
|
||||||
type containerInfo struct {
|
type containerInfo struct {
|
||||||
info.ContainerReference
|
info.ContainerReference
|
||||||
Subcontainers []info.ContainerReference
|
Subcontainers []info.ContainerReference
|
||||||
@ -67,6 +64,9 @@ type containerData struct {
|
|||||||
lastUpdatedTime time.Time
|
lastUpdatedTime time.Time
|
||||||
lastErrorTime time.Time
|
lastErrorTime time.Time
|
||||||
|
|
||||||
|
// Decay value used for load average smoothing. Interval length of 10 seconds is used.
|
||||||
|
loadDecay float64
|
||||||
|
|
||||||
// Whether to log the usage of this container when it is updated.
|
// Whether to log the usage of this container when it is updated.
|
||||||
logUsage bool
|
logUsage bool
|
||||||
|
|
||||||
@ -316,6 +316,8 @@ func newContainerData(containerName string, memoryCache *memory.InMemoryCache, h
|
|||||||
}
|
}
|
||||||
cont.info.ContainerReference = ref
|
cont.info.ContainerReference = ref
|
||||||
|
|
||||||
|
cont.loadDecay = math.Exp(float64(-cont.housekeepingInterval.Seconds() / 10))
|
||||||
|
|
||||||
err = cont.updateSpec()
|
err = cont.updateSpec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -460,7 +462,7 @@ func (c *containerData) updateLoad(newLoad uint64) {
|
|||||||
if c.loadAvg < 0 {
|
if c.loadAvg < 0 {
|
||||||
c.loadAvg = float64(newLoad) // initialize to the first seen sample for faster stabilization.
|
c.loadAvg = float64(newLoad) // initialize to the first seen sample for faster stabilization.
|
||||||
} else {
|
} else {
|
||||||
c.loadAvg = c.loadAvg*loadDecay + float64(newLoad)*(1.0-loadDecay)
|
c.loadAvg = c.loadAvg*c.loadDecay + float64(newLoad)*(1.0-c.loadDecay)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user