Added support for TLS-enabled Docker daemon
This commit is contained in:
parent
f543dbb42f
commit
b3ddde5a6f
|
@ -20,6 +20,11 @@ for the stat structure can be found
|
||||||
# To use TCP, set endpoint = "tcp://[ip]:[port]"
|
# To use TCP, set endpoint = "tcp://[ip]:[port]"
|
||||||
# To use environment variables (ie, docker-machine), set endpoint = "ENV"
|
# To use environment variables (ie, docker-machine), set endpoint = "ENV"
|
||||||
endpoint = "unix:///var/run/docker.sock"
|
endpoint = "unix:///var/run/docker.sock"
|
||||||
|
# To collect metrics from TLS-enabled daemon
|
||||||
|
# tls_enabled = true
|
||||||
|
# tls_ca = "~/certificates_path/ca.pem"
|
||||||
|
# tls_cert = "~/certificates_path/cert.pem"
|
||||||
|
# tls_key = "~/certificates_path/key.pem"
|
||||||
# Only collect metrics for these containers, collect all if empty
|
# Only collect metrics for these containers, collect all if empty
|
||||||
container_names = []
|
container_names = []
|
||||||
```
|
```
|
||||||
|
|
|
@ -14,12 +14,22 @@ import (
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
|
|
||||||
"github.com/fsouza/go-dockerclient"
|
"github.com/fsouza/go-dockerclient"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Docker struct {
|
type Docker struct {
|
||||||
Endpoint string
|
Endpoint string
|
||||||
ContainerNames []string
|
ContainerNames []string
|
||||||
|
|
||||||
|
// Enables TLS
|
||||||
|
TLSEnabled bool `toml:"tls_enabled"`
|
||||||
|
// Path to CA file
|
||||||
|
TLSCA string `toml:"tls_ca"`
|
||||||
|
// Path to cert file
|
||||||
|
TLSCert string `toml:"tls_cert"`
|
||||||
|
// Path to cert key file
|
||||||
|
TLSKey string `toml:"tls_key"`
|
||||||
|
|
||||||
client DockerClient
|
client DockerClient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +58,11 @@ var sampleConfig = `
|
||||||
## To use TCP, set endpoint = "tcp://[ip]:[port]"
|
## To use TCP, set endpoint = "tcp://[ip]:[port]"
|
||||||
## To use environment variables (ie, docker-machine), set endpoint = "ENV"
|
## To use environment variables (ie, docker-machine), set endpoint = "ENV"
|
||||||
endpoint = "unix:///var/run/docker.sock"
|
endpoint = "unix:///var/run/docker.sock"
|
||||||
|
## To collect metrics from TLS-enabled daemon
|
||||||
|
# tls_enabled = true
|
||||||
|
# tls_ca = "~/certificates_path/ca.pem"
|
||||||
|
# tls_cert = "~/certificates_path/cert.pem"
|
||||||
|
# tls_key = "~/certificates_path/key.pem"
|
||||||
## Only collect metrics for these containers, collect all if empty
|
## Only collect metrics for these containers, collect all if empty
|
||||||
container_names = []
|
container_names = []
|
||||||
`
|
`
|
||||||
|
@ -73,7 +88,24 @@ func (d *Docker) Gather(acc telegraf.Accumulator) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c, err = docker.NewClient(d.Endpoint)
|
if !d.TLSEnabled {
|
||||||
|
c, err = docker.NewClient(d.Endpoint)
|
||||||
|
} else {
|
||||||
|
if d.TLSCert == "" {
|
||||||
|
return errors.New("tls_cert must be configured when tls_enable is set to true");
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.TLSKey == "" {
|
||||||
|
return errors.New("tls_key must be configured when tls_enable is set to true");
|
||||||
|
}
|
||||||
|
|
||||||
|
if d.TLSCA == "" {
|
||||||
|
return errors.New("tls_ca must be configured when tls_enable is set to true");
|
||||||
|
}
|
||||||
|
|
||||||
|
c, err = docker.NewTLSClient(d.Endpoint, d.TLSCert, d.TLSKey, d.TLSCA)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue