Fix storage driver buffer duration default value.
The cache will now hold atlest the minimum number of stats required by the UI and more if the buffer duration is longer than the default. Docker-DCO-1.1-Signed-off-by: Vishnu Kannan <vishnuk@google.com> (github: vishh)
This commit is contained in:
parent
8e35f8f2e6
commit
1a24eed18f
@ -27,6 +27,9 @@ import (
|
|||||||
"github.com/google/cadvisor/storage"
|
"github.com/google/cadvisor/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Housekeeping duration
|
||||||
|
const HousekeepingTick = 1 * time.Second
|
||||||
|
|
||||||
// Internal mirror of the external data structure.
|
// Internal mirror of the external data structure.
|
||||||
type containerStat struct {
|
type containerStat struct {
|
||||||
Timestamp time.Time
|
Timestamp time.Time
|
||||||
@ -105,7 +108,7 @@ func NewContainerData(containerName string, driver storage.StorageDriver) (*cont
|
|||||||
|
|
||||||
func (c *containerData) housekeeping() {
|
func (c *containerData) housekeeping() {
|
||||||
// Housekeep every second.
|
// Housekeep every second.
|
||||||
ticker := time.NewTicker(1 * time.Second)
|
ticker := time.NewTicker(HousekeepingTick)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -92,6 +92,7 @@ function getMachineInfo(callback) {
|
|||||||
function getStats(containerName, callback) {
|
function getStats(containerName, callback) {
|
||||||
// Request 60s of container history and no samples.
|
// Request 60s of container history and no samples.
|
||||||
var request = JSON.stringify({
|
var request = JSON.stringify({
|
||||||
|
// Update main.statsRequestedByUI while updating "num_stats" here.
|
||||||
"num_stats": 60,
|
"num_stats": 60,
|
||||||
"num_samples": 0
|
"num_samples": 0
|
||||||
});
|
});
|
||||||
|
@ -20,6 +20,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
|
"github.com/google/cadvisor/manager"
|
||||||
"github.com/google/cadvisor/storage"
|
"github.com/google/cadvisor/storage"
|
||||||
"github.com/google/cadvisor/storage/cache"
|
"github.com/google/cadvisor/storage/cache"
|
||||||
"github.com/google/cadvisor/storage/influxdb"
|
"github.com/google/cadvisor/storage/influxdb"
|
||||||
@ -32,7 +34,9 @@ var argDbPassword = flag.String("storage_driver_password", "root", "database pas
|
|||||||
var argDbHost = flag.String("storage_driver_host", "localhost:8086", "database host:port")
|
var argDbHost = flag.String("storage_driver_host", "localhost:8086", "database host:port")
|
||||||
var argDbName = flag.String("storage_driver_db", "cadvisor", "database name")
|
var argDbName = flag.String("storage_driver_db", "cadvisor", "database name")
|
||||||
var argDbIsSecure = flag.Bool("storage_driver_secure", false, "use secure connection with database")
|
var argDbIsSecure = flag.Bool("storage_driver_secure", false, "use secure connection with database")
|
||||||
var argDbBufferDuration = flag.Duration("storage_driver_buffer_duration", 60, "Writes in the storage driver will be bufferd for this duration (in seconds), and committed to the non memory backends as a single transaction")
|
var argDbBufferDuration = flag.Duration("storage_driver_buffer_duration", 60*time.Second, "Writes in the storage driver will be bufferd for this duration, and committed to the non memory backends as a single transaction")
|
||||||
|
|
||||||
|
const statsRequestedByUI = 60
|
||||||
|
|
||||||
func NewStorageDriver(driverName string) (storage.StorageDriver, error) {
|
func NewStorageDriver(driverName string) (storage.StorageDriver, error) {
|
||||||
var storageDriver storage.StorageDriver
|
var storageDriver storage.StorageDriver
|
||||||
@ -63,7 +67,13 @@ func NewStorageDriver(driverName string) (storage.StorageDriver, error) {
|
|||||||
// TODO(monnand): One hour? Or user-defined?
|
// TODO(monnand): One hour? Or user-defined?
|
||||||
1*time.Hour,
|
1*time.Hour,
|
||||||
)
|
)
|
||||||
storageDriver = cache.MemoryCache(int(*argDbBufferDuration), int(*argDbBufferDuration), storageDriver)
|
samplesToCache := int(*argDbBufferDuration / manager.HousekeepingTick)
|
||||||
|
if samplesToCache < statsRequestedByUI {
|
||||||
|
// The UI requests the most recent 60 stats by default.
|
||||||
|
samplesToCache = statsRequestedByUI
|
||||||
|
}
|
||||||
|
glog.V(2).Infof("Caching %d recent stats in memory\n", samplesToCache)
|
||||||
|
storageDriver = cache.MemoryCache(samplesToCache, samplesToCache, storageDriver)
|
||||||
default:
|
default:
|
||||||
err = fmt.Errorf("Unknown database driver: %v", *argDbDriver)
|
err = fmt.Errorf("Unknown database driver: %v", *argDbDriver)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user