Beispiel #1
0
func NewStorageDriver(driverName string) (storage.StorageDriver, error) {
	var storageDriver storage.StorageDriver
	var err error
	// TODO(vmarmol): We shouldn't need the housekeeping interval here and it shouldn't be public.
	samplesToCache := int(*argDbBufferDuration / *manager.HousekeepingInterval)
	if samplesToCache < statsRequestedByUI {
		// The UI requests the most recent 60 stats by default.
		samplesToCache = statsRequestedByUI
	}
	switch driverName {
	case "":
		// empty string by default is the in memory store
		fallthrough
	case "memory":
		storageDriver = memory.New(*argSampleSize, int(*argDbBufferDuration))
		return storageDriver, nil
	case "influxdb":
		var hostname string
		hostname, err = os.Hostname()
		if err != nil {
			return nil, err
		}

		storageDriver, err = influxdb.New(
			hostname,
			"stats",
			*argDbName,
			*argDbUsername,
			*argDbPassword,
			*argDbHost,
			*argDbIsSecure,
			*argDbBufferDuration,
			// TODO(monnand): One hour? Or user-defined?
			1*time.Hour,
		)
		glog.V(2).Infof("Caching %d recent stats in memory\n", samplesToCache)
		storageDriver = cache.MemoryCache(samplesToCache, samplesToCache, storageDriver)
	case "bigquery":
		var hostname string
		hostname, err = os.Hostname()
		if err != nil {
			return nil, err
		}
		storageDriver, err = bigquery.New(
			hostname,
			"cadvisor",
			*argDbName,
			1*time.Hour,
		)
		glog.V(2).Infof("Caching %d recent stats in memory\n", samplesToCache)
		storageDriver = cache.MemoryCache(samplesToCache, samplesToCache, storageDriver)

	default:
		err = fmt.Errorf("Unknown database driver: %v", *argDbDriver)
	}
	if err != nil {
		return nil, err
	}
	return storageDriver, nil
}
Beispiel #2
0
func NewStorageDriver(driverName string) (storage.StorageDriver, error) {
	var storageDriver storage.StorageDriver
	var err error
	switch driverName {
	case "":
		// empty string by default is the in memory store
		fallthrough
	case "memory":
		storageDriver = memory.New(*argSampleSize, *argHistoryDuration)
		return storageDriver, nil
	case "influxdb":
		var hostname string
		hostname, err = os.Hostname()
		if err != nil {
			return nil, err
		}

		storageDriver, err = influxdb.New(
			hostname,
			"cadvisorTable",
			*argDbName,
			*argDbUsername,
			*argDbPassword,
			*argDbHost,
			*argDbIsSecure,
			// TODO(monnand): One hour? Or user-defined?
			1*time.Hour,
		)
		storageDriver = cache.MemoryCache(*argHistoryDuration, *argHistoryDuration, storageDriver)
	default:
		err = fmt.Errorf("Unknown database driver: %v", *argDbDriver)
	}
	if err != nil {
		return nil, err
	}
	return storageDriver, nil
}