Allow customizing storage duration.

This commit is contained in:
Victor Marmol 2015-04-21 12:37:26 -07:00
parent d9f8a0920c
commit 5fd8273806
3 changed files with 12 additions and 12 deletions

View File

@ -2,6 +2,14 @@
This document describes a set of runtime flags available in cAdvisor.
## Local Storage Duration
cAdvisor stores the latest historical data in memory. How long of a history it stores can be configured with the `--storage_duration` flag.
```
--storage_duration: How long to store data.
```
## Housekeeping
Housekeeping is the periodic actions cAdvisor takes. During these actions, cAdvisor will gather container stats. These flags control how and when cAdvisor performs housekeeping.

View File

@ -81,7 +81,7 @@ func expectManagerWithContainers(containers []string, query *info.ContainerInfoR
infosMap[container] = itest.GenerateRandomContainerInfo(container, 4, query, 1*time.Second)
}
memoryStorage := memory.New(query.NumStats, nil)
memoryStorage := memory.New(time.Duration(query.NumStats)*time.Second, nil)
sysfs := &fakesysfs.FakeSysFs{}
m := createManagerAndAddContainers(
memoryStorage,

View File

@ -21,7 +21,6 @@ import (
"time"
"github.com/golang/glog"
"github.com/google/cadvisor/manager"
"github.com/google/cadvisor/storage"
"github.com/google/cadvisor/storage/bigquery"
"github.com/google/cadvisor/storage/influxdb"
@ -35,20 +34,13 @@ var argDbName = flag.String("storage_driver_db", "cadvisor", "database name")
var argDbTable = flag.String("storage_driver_table", "stats", "table name")
var argDbIsSecure = flag.Bool("storage_driver_secure", false, "use secure connection with database")
var argDbBufferDuration = flag.Duration("storage_driver_buffer_duration", 60*time.Second, "Writes in the storage driver will be buffered for this duration, and committed to the non memory backends as a single transaction")
const statsRequestedByUI = 60
var storageDuration = flag.Duration("storage_duration", 2*time.Minute, "How long to keep data stored (Default: 2min).")
// Creates a memory storage with an optional backend storage option.
func NewMemoryStorage(backendStorageName string) (*memory.InMemoryStorage, error) {
var storageDriver *memory.InMemoryStorage
var backendStorage storage.StorageDriver
var err error
// TODO(vmarmol): We shouldn't need the housekeeping interval here and it shouldn't be public.
statsToCache := int(*argDbBufferDuration / *manager.HousekeepingInterval)
if statsToCache < statsRequestedByUI {
// The UI requests the most recent 60 stats by default.
statsToCache = statsRequestedByUI
}
switch backendStorageName {
case "":
backendStorage = nil
@ -91,7 +83,7 @@ func NewMemoryStorage(backendStorageName string) (*memory.InMemoryStorage, error
} else {
glog.Infof("No backend storage selected")
}
glog.Infof("Caching %d stats in memory", statsToCache)
storageDriver = memory.New(time.Duration(statsToCache)*time.Second, backendStorage)
glog.Infof("Caching stats in memory for %v", *storageDuration)
storageDriver = memory.New(*storageDuration, backendStorage)
return storageDriver, nil
}