Moved max_housekeeping and allow_dynamic_housekeeping flags to cadvisor.go
This commit is contained in:
parent
5853f97295
commit
90ca5f9286
@ -23,6 +23,7 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
cadvisorHttp "github.com/google/cadvisor/http"
|
cadvisorHttp "github.com/google/cadvisor/http"
|
||||||
@ -45,6 +46,9 @@ var httpDigestRealm = flag.String("http_digest_realm", "localhost", "HTTP digest
|
|||||||
|
|
||||||
var prometheusEndpoint = flag.String("prometheus_endpoint", "/metrics", "Endpoint to expose Prometheus metrics on")
|
var prometheusEndpoint = flag.String("prometheus_endpoint", "/metrics", "Endpoint to expose Prometheus metrics on")
|
||||||
|
|
||||||
|
var maxHousekeepingInterval = flag.Duration("max_housekeeping_interval", 60*time.Second, "Largest interval to allow between container housekeepings")
|
||||||
|
var allowDynamicHousekeeping = flag.Bool("allow_dynamic_housekeeping", true, "Whether to allow the housekeeping interval to be dynamic")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
defer glog.Flush()
|
defer glog.Flush()
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
@ -66,7 +70,7 @@ func main() {
|
|||||||
glog.Fatalf("Failed to create a system interface: %s", err)
|
glog.Fatalf("Failed to create a system interface: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
containerManager, err := manager.New(memoryStorage, sysFs)
|
containerManager, err := manager.New(memoryStorage, sysFs, *maxHousekeepingInterval, *allowDynamicHousekeeping)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Failed to create a Container Manager: %s", err)
|
glog.Fatalf("Failed to create a Container Manager: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,6 @@ import (
|
|||||||
|
|
||||||
// Housekeeping interval.
|
// Housekeeping interval.
|
||||||
var HousekeepingInterval = flag.Duration("housekeeping_interval", 1*time.Second, "Interval between container housekeepings")
|
var HousekeepingInterval = flag.Duration("housekeeping_interval", 1*time.Second, "Interval between container housekeepings")
|
||||||
var maxHousekeepingInterval = flag.Duration("max_housekeeping_interval", 60*time.Second, "Largest interval to allow between container housekeepings")
|
|
||||||
var allowDynamicHousekeeping = flag.Bool("allow_dynamic_housekeeping", true, "Whether to allow the housekeeping interval to be dynamic")
|
|
||||||
|
|
||||||
var cgroupPathRegExp = regexp.MustCompile(".*:devices:(.*?),.*")
|
var cgroupPathRegExp = regexp.MustCompile(".*:devices:(.*?),.*")
|
||||||
|
|
||||||
@ -62,6 +60,8 @@ type containerData struct {
|
|||||||
summaryReader *summary.StatsSummary
|
summaryReader *summary.StatsSummary
|
||||||
loadAvg float64 // smoothed load average seen so far.
|
loadAvg float64 // smoothed load average seen so far.
|
||||||
housekeepingInterval time.Duration
|
housekeepingInterval time.Duration
|
||||||
|
maxHousekeepingInterval time.Duration
|
||||||
|
allowDynamicHousekeeping bool
|
||||||
lastUpdatedTime time.Time
|
lastUpdatedTime time.Time
|
||||||
lastErrorTime time.Time
|
lastErrorTime time.Time
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ func (c *containerData) GetProcessList(cadvisorContainer string, inHostNamespace
|
|||||||
return processes, nil
|
return processes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newContainerData(containerName string, memoryCache *memory.InMemoryCache, handler container.ContainerHandler, loadReader cpuload.CpuLoadReader, logUsage bool, collectorManager collector.CollectorManager) (*containerData, error) {
|
func newContainerData(containerName string, memoryCache *memory.InMemoryCache, handler container.ContainerHandler, loadReader cpuload.CpuLoadReader, logUsage bool, collectorManager collector.CollectorManager, maxHousekeepingInterval time.Duration, allowDynamicHousekeeping bool) (*containerData, error) {
|
||||||
if memoryCache == nil {
|
if memoryCache == nil {
|
||||||
return nil, fmt.Errorf("nil memory storage")
|
return nil, fmt.Errorf("nil memory storage")
|
||||||
}
|
}
|
||||||
@ -237,6 +237,8 @@ func newContainerData(containerName string, memoryCache *memory.InMemoryCache, h
|
|||||||
handler: handler,
|
handler: handler,
|
||||||
memoryCache: memoryCache,
|
memoryCache: memoryCache,
|
||||||
housekeepingInterval: *HousekeepingInterval,
|
housekeepingInterval: *HousekeepingInterval,
|
||||||
|
maxHousekeepingInterval: maxHousekeepingInterval,
|
||||||
|
allowDynamicHousekeeping: allowDynamicHousekeeping,
|
||||||
loadReader: loadReader,
|
loadReader: loadReader,
|
||||||
logUsage: logUsage,
|
logUsage: logUsage,
|
||||||
loadAvg: -1.0, // negative value indicates uninitialized.
|
loadAvg: -1.0, // negative value indicates uninitialized.
|
||||||
@ -260,7 +262,7 @@ func newContainerData(containerName string, memoryCache *memory.InMemoryCache, h
|
|||||||
|
|
||||||
// Determine when the next housekeeping should occur.
|
// Determine when the next housekeeping should occur.
|
||||||
func (self *containerData) nextHousekeeping(lastHousekeeping time.Time) time.Time {
|
func (self *containerData) nextHousekeeping(lastHousekeeping time.Time) time.Time {
|
||||||
if *allowDynamicHousekeeping {
|
if self.allowDynamicHousekeeping {
|
||||||
var empty time.Time
|
var empty time.Time
|
||||||
stats, err := self.memoryCache.RecentStats(self.info.Name, empty, empty, 2)
|
stats, err := self.memoryCache.RecentStats(self.info.Name, empty, empty, 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -270,10 +272,10 @@ func (self *containerData) nextHousekeeping(lastHousekeeping time.Time) time.Tim
|
|||||||
} else if len(stats) == 2 {
|
} else if len(stats) == 2 {
|
||||||
// TODO(vishnuk): Use no processes as a signal.
|
// TODO(vishnuk): Use no processes as a signal.
|
||||||
// Raise the interval if usage hasn't changed in the last housekeeping.
|
// Raise the interval if usage hasn't changed in the last housekeeping.
|
||||||
if stats[0].StatsEq(stats[1]) && (self.housekeepingInterval < *maxHousekeepingInterval) {
|
if stats[0].StatsEq(stats[1]) && (self.housekeepingInterval < self.maxHousekeepingInterval) {
|
||||||
self.housekeepingInterval *= 2
|
self.housekeepingInterval *= 2
|
||||||
if self.housekeepingInterval > *maxHousekeepingInterval {
|
if self.housekeepingInterval > self.maxHousekeepingInterval {
|
||||||
self.housekeepingInterval = *maxHousekeepingInterval
|
self.housekeepingInterval = self.maxHousekeepingInterval
|
||||||
}
|
}
|
||||||
} else if self.housekeepingInterval != *HousekeepingInterval {
|
} else if self.housekeepingInterval != *HousekeepingInterval {
|
||||||
// Lower interval back to the baseline.
|
// Lower interval back to the baseline.
|
||||||
|
@ -41,7 +41,7 @@ func setupContainerData(t *testing.T, spec info.ContainerSpec) (*containerData,
|
|||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
memoryCache := memory.New(60, nil)
|
memoryCache := memory.New(60, nil)
|
||||||
ret, err := newContainerData(containerName, memoryCache, mockHandler, nil, false, &collector.GenericCollectorManager{})
|
ret, err := newContainerData(containerName, memoryCache, mockHandler, nil, false, &collector.GenericCollectorManager{}, 60*time.Second, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -114,7 +114,7 @@ type Manager interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// New takes a memory storage and returns a new manager.
|
// New takes a memory storage and returns a new manager.
|
||||||
func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs) (Manager, error) {
|
func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingInterval time.Duration, allowDynamicHousekeeping bool) (Manager, error) {
|
||||||
if memoryCache == nil {
|
if memoryCache == nil {
|
||||||
return nil, fmt.Errorf("manager requires memory storage")
|
return nil, fmt.Errorf("manager requires memory storage")
|
||||||
}
|
}
|
||||||
@ -146,6 +146,8 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs) (Manager, error)
|
|||||||
cadvisorContainer: selfContainer,
|
cadvisorContainer: selfContainer,
|
||||||
inHostNamespace: inHostNamespace,
|
inHostNamespace: inHostNamespace,
|
||||||
startupTime: time.Now(),
|
startupTime: time.Now(),
|
||||||
|
maxHousekeepingInterval: maxHousekeepingInterval,
|
||||||
|
allowDynamicHousekeeping: allowDynamicHousekeeping,
|
||||||
}
|
}
|
||||||
|
|
||||||
machineInfo, err := getMachineInfo(sysfs, fsInfo)
|
machineInfo, err := getMachineInfo(sysfs, fsInfo)
|
||||||
@ -189,6 +191,8 @@ type manager struct {
|
|||||||
loadReader cpuload.CpuLoadReader
|
loadReader cpuload.CpuLoadReader
|
||||||
eventHandler events.EventManager
|
eventHandler events.EventManager
|
||||||
startupTime time.Time
|
startupTime time.Time
|
||||||
|
maxHousekeepingInterval time.Duration
|
||||||
|
allowDynamicHousekeeping bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the container manager.
|
// Start the container manager.
|
||||||
@ -706,7 +710,7 @@ func (m *manager) createContainer(containerName string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logUsage := *logCadvisorUsage && containerName == m.cadvisorContainer
|
logUsage := *logCadvisorUsage && containerName == m.cadvisorContainer
|
||||||
cont, err := newContainerData(containerName, m.memoryCache, handler, m.loadReader, logUsage, collectorManager)
|
cont, err := newContainerData(containerName, m.memoryCache, handler, m.loadReader, logUsage, collectorManager, m.maxHousekeepingInterval, m.allowDynamicHousekeeping)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ func createManagerAndAddContainers(
|
|||||||
spec,
|
spec,
|
||||||
nil,
|
nil,
|
||||||
).Once()
|
).Once()
|
||||||
cont, err := newContainerData(name, memoryCache, mockHandler, nil, false, &collector.GenericCollectorManager{})
|
cont, err := newContainerData(name, memoryCache, mockHandler, nil, false, &collector.GenericCollectorManager{}, 60*time.Second, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -205,7 +205,7 @@ func TestDockerContainersInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNewNilManager(t *testing.T) {
|
func TestNewNilManager(t *testing.T) {
|
||||||
_, err := New(nil, nil)
|
_, err := New(nil, nil, 60*time.Second, true)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Expected nil manager to return error")
|
t.Fatalf("Expected nil manager to return error")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user