Esempio n. 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
}
Esempio n. 2
0
func NewStorageDriver(driverName 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.
	samplesToCache := int(*argDbBufferDuration / *manager.HousekeepingInterval)
	if samplesToCache < statsRequestedByUI {
		// The UI requests the most recent 60 stats by default.
		samplesToCache = statsRequestedByUI
	}
	switch driverName {
	case "":
		backendStorage = nil
	case "influxdb":
		var hostname string
		hostname, err = os.Hostname()
		if err != nil {
			return nil, err
		}

		backendStorage, err = influxdb.New(
			hostname,
			"stats",
			*argDbName,
			*argDbUsername,
			*argDbPassword,
			*argDbHost,
			*argDbIsSecure,
			*argDbBufferDuration,
			// TODO(monnand): One hour? Or user-defined?
			1*time.Hour,
		)
	case "bigquery":
		var hostname string
		hostname, err = os.Hostname()
		if err != nil {
			return nil, err
		}
		backendStorage, err = bigquery.New(
			hostname,
			"cadvisor",
			*argDbName,
			1*time.Hour,
		)

	default:
		err = fmt.Errorf("Unknown database driver: %v", *argDbDriver)
	}
	if err != nil {
		return nil, err
	}
	glog.Infof("Caching %d recent stats in memory; using \"%v\" storage driver\n", samplesToCache, driverName)
	storageDriver = memory.New(samplesToCache, samplesToCache, backendStorage)
	return storageDriver, nil
}
Esempio n. 3
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
}
Esempio n. 4
0
// Creates a memory storage with an optional backend storage option.
func NewMemoryStorage(backendStorageName string) (*memory.InMemoryCache, error) {
	var storageDriver *memory.InMemoryCache
	var backendStorage storage.StorageDriver
	var err error
	switch backendStorageName {
	case "":
		backendStorage = nil
	case "influxdb":
		var hostname string
		hostname, err = os.Hostname()
		if err != nil {
			return nil, err
		}

		backendStorage, err = influxdb.New(
			hostname,
			*argDbTable,
			*argDbName,
			*argDbUsername,
			*argDbPassword,
			*argDbHost,
			*argDbIsSecure,
			*argDbBufferDuration,
		)
	case "bigquery":
		var hostname string
		hostname, err = os.Hostname()
		if err != nil {
			return nil, err
		}
		backendStorage, err = bigquery.New(
			hostname,
			*argDbTable,
			*argDbName,
		)
	case "redis":
		//machineName: We use os.Hostname as the machineName (A unique identifier to identify the host that runs the current cAdvisor)
		//argDbName: the key for redis's data
		//argDbHost: the redis's server host
		var machineName string
		machineName, err = os.Hostname()
		if err != nil {
			return nil, err
		}
		backendStorage, err = redis.New(
			machineName,
			*argDbName,
			*argDbHost,
			*argDbBufferDuration,
		)
	case "elasticsearch":
		//argIndexName: the index for elasticsearch
		//argTypeName: the type for index
		//argElasticHost: the elasticsearch's server host
		var machineName string
		machineName, err = os.Hostname()
		if err != nil {
			return nil, err
		}
		backendStorage, err = elasticsearch.New(
			machineName,
			*argIndexName,
			*argTypeName,
			*argElasticHost,
			*argEnableSniffer,
		)
	case "statsd":
		backendStorage, err = statsd.New(
			*argDbName,
			*argDbHost,
		)
	case "stdout":
		backendStorage, err = stdout.New(
			*argDbHost,
		)
	default:
		err = fmt.Errorf("unknown backend storage driver: %v", *argDbDriver)
	}
	if err != nil {
		return nil, err
	}
	if backendStorageName != "" {
		glog.Infof("Using backend storage type %q", backendStorageName)
	} else {
		glog.Infof("No backend storage selected")
	}
	glog.Infof("Caching stats in memory for %v", *storageDuration)
	storageDriver = memory.New(*storageDuration, backendStorage)
	return storageDriver, nil
}