diff --git a/README.md b/README.md index 2b1555c2..dc4b9c91 100644 --- a/README.md +++ b/README.md @@ -32,15 +32,9 @@ We have detailed [instructions](docs/running.md#standalone) on running cAdvisor See the more detailed instructions in the [build page](docs/development/build.md). This includes instructions for building and deploying the cAdvisor Docker image. -## InfluxDB and Cluster Monitoring +## Exporting stats -cAdvisor supports exporting stats to [InfluxDB](https://influxdb.com/). See the [documentation](docs/influxdb.md) for more information and examples. - -cAdvisor also exposes container stats as [Prometheus](http://prometheus.io) metrics. See the [documentation](docs/prometheus.md) for more information. - -cAdvisor also supports exporting stats to [ElasticSearch](https://www.elastic.co/). See the [documentation](docs/elasticsearch.md) for more information. - -[Heapster](https://github.com/kubernetes/heapster) enables cluster wide monitoring of containers using cAdvisor. +cAdvisor supports exporting stats to various storage plugins. See the [documentation](docs/storage/README.md) for more details and examples. ## Web UI diff --git a/cadvisor.go b/cadvisor.go index f52ac901..6d80a049 100644 --- a/cadvisor.go +++ b/cadvisor.go @@ -39,7 +39,6 @@ var argIp = flag.String("listen_ip", "", "IP to listen on, defaults to all IPs") var argPort = flag.Int("port", 8080, "port to listen") var maxProcs = flag.Int("max_procs", 0, "max number of CPUs that can be used simultaneously. Less than 1 for default (number of cores).") -var argDbDriver = flag.String("storage_driver", "", "storage driver to use. Data is always cached shortly in memory, this controls where data is pushed besides the local cache. Empty means none. Options are: (default), bigquery, influxdb, and kafka") var versionFlag = flag.Bool("version", false, "print cAdvisor version and exit") var httpAuthFile = flag.String("http_auth_file", "", "HTTP auth file for the web UI") @@ -109,9 +108,9 @@ func main() { setMaxProcs() - memoryStorage, err := NewMemoryStorage(*argDbDriver) + memoryStorage, err := NewMemoryStorage() if err != nil { - glog.Fatalf("Failed to connect to database: %s", err) + glog.Fatalf("Failed to initialize storage driver: %s", err) } sysFs, err := sysfs.NewRealSysFs() diff --git a/docs/storage/README.md b/docs/storage/README.md new file mode 100644 index 00000000..f3c05737 --- /dev/null +++ b/docs/storage/README.md @@ -0,0 +1,14 @@ +# cAdvisor Storage Plugins + +cAdvisor supports exporting stats to various storage driver plugins. To enable a storage driver, set the `-storage_driver` flag. + +## Storage drivers + +- [BigQuery](https://cloud.google.com/bigquery/). See the [documentation](../../storage/bigquery/README.md) for usage. +- [ElasticSearch](https://www.elastic.co/). See the [documentation](elasticsearch.md) for usage and examples. +- [InfluxDB](https://influxdb.com/). See the [documentation](influxdb.md) for usage and examples. +- [Kafka](http://kafka.apache.org/) +- [Prometheus](http://prometheus.io). See the [documentation](prometheus.md) for usage and examples. +- [Redis](http://redis.io/) +- [StatsD](https://github.com/etsy/statsd) +- `stdout` - write stats to standard output. diff --git a/docs/elasticsearch.md b/docs/storage/elasticsearch.md similarity index 100% rename from docs/elasticsearch.md rename to docs/storage/elasticsearch.md diff --git a/docs/influxdb.md b/docs/storage/influxdb.md similarity index 100% rename from docs/influxdb.md rename to docs/storage/influxdb.md diff --git a/docs/prometheus.md b/docs/storage/prometheus.md similarity index 100% rename from docs/prometheus.md rename to docs/storage/prometheus.md diff --git a/storage/storage.go b/storage/storage.go index 1a0dccf0..b420d4b1 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -16,6 +16,7 @@ package storage import ( "fmt" + "sort" info "github.com/google/cadvisor/info/v1" ) @@ -47,3 +48,12 @@ func New(name string) (StorageDriver, error) { } return f() } + +func ListDrivers() []string { + drivers := make([]string, 0, len(registeredPlugins)) + for name := range registeredPlugins { + drivers = append(drivers, name) + } + sort.Strings(drivers) + return drivers +} diff --git a/storagedriver.go b/storagedriver.go index 6da3b305..a72bc144 100644 --- a/storagedriver.go +++ b/storagedriver.go @@ -16,6 +16,8 @@ package main import ( "flag" + "fmt" + "strings" "time" "github.com/google/cadvisor/cache/memory" @@ -31,18 +33,20 @@ import ( "github.com/golang/glog" ) -var storageDuration = flag.Duration("storage_duration", 2*time.Minute, "How long to keep data stored (Default: 2min).") +var ( + storageDriver = flag.String("storage_driver", "", fmt.Sprintf("Storage `driver` to use. Data is always cached shortly in memory, this controls where data is pushed besides the local cache. Empty means none. Options are: , %s", strings.Join(storage.ListDrivers(), ", "))) + storageDuration = flag.Duration("storage_duration", 2*time.Minute, "How long to keep data stored (Default: 2min).") +) // NewMemoryStorage creates a memory storage with an optional backend storage option. -func NewMemoryStorage(backendStorageName string) (*memory.InMemoryCache, error) { - backendStorage, err := storage.New(backendStorageName) +func NewMemoryStorage() (*memory.InMemoryCache, error) { + backendStorage, err := storage.New(*storageDriver) if err != nil { return nil, err } - if backendStorageName != "" { - glog.Infof("Using backend storage type %q", backendStorageName) + if *storageDriver != "" { + glog.Infof("Using backend storage type %q", *storageDriver) } glog.Infof("Caching stats in memory for %v", *storageDuration) - storageDriver := memory.New(*storageDuration, backendStorage) - return storageDriver, nil + return memory.New(*storageDuration, backendStorage), nil }