2016-01-20 23:21:19 +00:00
|
|
|
package system
|
|
|
|
|
|
|
|
import (
|
2016-01-27 21:21:36 +00:00
|
|
|
"github.com/influxdata/telegraf"
|
2016-01-26 22:16:46 +00:00
|
|
|
docker "github.com/influxdata/telegraf/internal/docker"
|
2016-01-20 23:21:19 +00:00
|
|
|
"github.com/influxdata/telegraf/plugins/inputs"
|
|
|
|
|
2016-01-26 22:16:46 +00:00
|
|
|
godocker "github.com/fsouza/go-dockerclient"
|
2016-01-20 23:21:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Docker struct {
|
|
|
|
Endpoint string
|
|
|
|
ContainerNames []string
|
2016-01-26 22:16:46 +00:00
|
|
|
client *godocker.Client
|
2016-01-20 23:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var sampleConfig = `
|
|
|
|
# Docker Endpoint
|
|
|
|
# To use TCP, set endpoint = "tcp://[ip]:[port]"
|
|
|
|
# To use environment variables (ie, docker-machine), set endpoint = "ENV"
|
|
|
|
endpoint = "unix:///var/run/docker.sock"
|
|
|
|
# Only collect metrics for these containers, collect all if empty
|
|
|
|
container_names = []
|
|
|
|
`
|
|
|
|
|
|
|
|
func (d *Docker) Description() string {
|
|
|
|
return "Read metrics about docker containers"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Docker) SampleConfig() string { return sampleConfig }
|
|
|
|
|
2016-01-27 21:21:36 +00:00
|
|
|
func (d *Docker) Gather(acc telegraf.Accumulator) error {
|
2016-01-26 22:16:46 +00:00
|
|
|
var err error
|
2016-01-20 23:21:19 +00:00
|
|
|
|
2016-01-26 22:16:46 +00:00
|
|
|
d.client, err = docker.CreateClient(d.Endpoint)
|
2016-01-20 23:21:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-01-26 22:16:46 +00:00
|
|
|
if d.client != nil {
|
|
|
|
err = docker.GatherContainerMetrics(d.client, nil, d.ContainerNames, acc)
|
2016-01-20 23:21:19 +00:00
|
|
|
}
|
2016-01-26 22:16:46 +00:00
|
|
|
return err
|
2016-01-20 23:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-01-27 21:21:36 +00:00
|
|
|
inputs.Add("docker", func() telegraf.Input {
|
2016-01-20 23:21:19 +00:00
|
|
|
return &Docker{}
|
|
|
|
})
|
|
|
|
}
|