1
0
Fork 0

Adding upstream version 1.34.4.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-24 07:26:29 +02:00
parent e393c3af3f
commit 4978089aab
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
4963 changed files with 677545 additions and 0 deletions

View file

@ -0,0 +1,414 @@
# Docker Input Plugin
This plugin uses the [Docker Engine API][api] to gather metrics on running
docker containers.
> [!NOTE]
> Please make sure Telegraf has sufficient permissions to access the configured
> endpoint!
⭐ Telegraf v0.1.9
🏷️ containers
💻 all
[api]: https://docs.docker.com/engine/api
## Global configuration options <!-- @/docs/includes/plugin_config.md -->
In addition to the plugin-specific configuration settings, plugins support
additional global and plugin configuration settings. These settings are used to
modify metrics, tags, and field or create aliases and configure ordering, etc.
See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
[CONFIGURATION.md]: ../../../docs/CONFIGURATION.md#plugins
## Configuration
```toml @sample.conf
# Read metrics about docker containers
[[inputs.docker]]
## 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"
## Set to true to collect Swarm metrics(desired_replicas, running_replicas)
## Note: configure this in one of the manager nodes in a Swarm cluster.
## configuring in multiple Swarm managers results in duplication of metrics.
gather_services = false
## Only collect metrics for these containers. Values will be appended to
## container_name_include.
## Deprecated (1.4.0), use container_name_include
container_names = []
## Set the source tag for the metrics to the container ID hostname, eg first 12 chars
source_tag = false
## Containers to include and exclude. Collect all if empty. Globs accepted.
container_name_include = []
container_name_exclude = []
## Container states to include and exclude. Globs accepted.
## When empty only containers in the "running" state will be captured.
## example: container_state_include = ["created", "restarting", "running", "removing", "paused", "exited", "dead"]
## example: container_state_exclude = ["created", "restarting", "running", "removing", "paused", "exited", "dead"]
# container_state_include = []
# container_state_exclude = []
## Objects to include for disk usage query
## Allowed values are "container", "image", "volume"
## When empty disk usage is excluded
storage_objects = []
## Timeout for docker list, info, and stats commands
timeout = "5s"
## Specifies for which classes a per-device metric should be issued
## Possible values are 'cpu' (cpu0, cpu1, ...), 'blkio' (8:0, 8:1, ...) and 'network' (eth0, eth1, ...)
## Please note that this setting has no effect if 'perdevice' is set to 'true'
# perdevice_include = ["cpu"]
## Specifies for which classes a total metric should be issued. Total is an aggregated of the 'perdevice' values.
## Possible values are 'cpu', 'blkio' and 'network'
## Total 'cpu' is reported directly by Docker daemon, and 'network' and 'blkio' totals are aggregated by this plugin.
## Please note that this setting has no effect if 'total' is set to 'false'
# total_include = ["cpu", "blkio", "network"]
## docker labels to include and exclude as tags. Globs accepted.
## Note that an empty array for both will include all labels as tags
docker_label_include = []
docker_label_exclude = []
## Which environment variables should we use as a tag
tag_env = ["JAVA_HOME", "HEAP_SIZE"]
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false
```
### Environment Configuration
When using the `"ENV"` endpoint, the connection is configured using the [cli
Docker environment variables][3].
[3]: https://godoc.org/github.com/moby/moby/client#NewEnvClient
### Security
Giving telegraf access to the Docker daemon expands the [attack surface][4] that
could result in an attacker gaining root access to a machine. This is especially
relevant if the telegraf configuration can be changed by untrusted users.
[4]: https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
### Docker Daemon Permissions
Typically, telegraf must be given permission to access the docker daemon unix
socket when using the default endpoint. This can be done by adding the
`telegraf` unix user (created when installing a Telegraf package) to the
`docker` unix group with the following command:
```shell
sudo usermod -aG docker telegraf
```
If telegraf is run within a container, the unix socket will need to be exposed
within the telegraf container. This can be done in the docker CLI by add the
option `-v /var/run/docker.sock:/var/run/docker.sock` or adding the following
lines to the telegraf container definition in a docker compose file.
Additionally docker `telegraf` user must be assigned to `docker` group id
from host:
```yaml
user: telegraf:<host_docker_gid>
volumes:
- /var/run/docker.sock:/var/run/docker.sock
```
### source tag
Selecting the containers measurements can be tricky if you have many containers
with the same name. To alleviate this issue you can set the below value to
`true`
```toml
source_tag = true
```
This will cause all measurements to have the `source` tag be set to the first 12
characters of the container id. The first 12 characters is the common hostname
for containers that have no explicit hostname set, as defined by docker.
### Kubernetes Labels
Kubernetes may add many labels to your containers, if they are not needed you
may prefer to exclude them:
```json
docker_label_exclude = ["annotation.kubernetes*"]
```
### Docker-compose Labels
Docker-compose will add labels to your containers. You can limit restrict labels
to selected ones, e.g.
```json
docker_label_include = [
"com.docker.compose.config-hash",
"com.docker.compose.container-number",
"com.docker.compose.oneoff",
"com.docker.compose.project",
"com.docker.compose.service",
]
```
## Metrics
- docker
- tags:
- unit
- engine_host
- server_version
- fields:
- n_used_file_descriptors
- n_cpus
- n_containers
- n_containers_running
- n_containers_stopped
- n_containers_paused
- n_images
- n_goroutines
- n_listener_events
- memory_total
- pool_blocksize (requires devicemapper storage driver) (deprecated see: `docker_devicemapper`)
The `docker_data` and `docker_metadata` measurements are available only for
some storage drivers such as devicemapper.
- docker_data (deprecated see: `docker_devicemapper`)
- tags:
- unit
- engine_host
- server_version
- fields:
- available
- total
- used
- docker_metadata (deprecated see: `docker_devicemapper`)
- tags:
- unit
- engine_host
- server_version
- fields:
- available
- total
- used
The above measurements for the devicemapper storage driver can now be found in
the new `docker_devicemapper` measurement
- docker_devicemapper
- tags:
- engine_host
- server_version
- pool_name
- fields:
- pool_blocksize_bytes
- data_space_used_bytes
- data_space_total_bytes
- data_space_available_bytes
- metadata_space_used_bytes
- metadata_space_total_bytes
- metadata_space_available_bytes
- thin_pool_minimum_free_space_bytes
- docker_container_mem
- tags:
- engine_host
- server_version
- container_image
- container_name
- container_status
- container_version
- fields:
- total_pgmajfault
- cache
- mapped_file
- total_inactive_file
- pgpgout
- rss
- total_mapped_file
- writeback
- unevictable
- pgpgin
- total_unevictable
- pgmajfault
- total_rss
- total_rss_huge
- total_writeback
- total_inactive_anon
- rss_huge
- hierarchical_memory_limit
- total_pgfault
- total_active_file
- active_anon
- total_active_anon
- total_pgpgout
- total_cache
- inactive_anon
- active_file
- pgfault
- inactive_file
- total_pgpgin
- max_usage
- usage
- failcnt
- limit
- container_id
- docker_container_cpu
- tags:
- engine_host
- server_version
- container_image
- container_name
- container_status
- container_version
- cpu
- fields:
- throttling_periods
- throttling_throttled_periods
- throttling_throttled_time
- usage_in_kernelmode
- usage_in_usermode
- usage_system
- usage_total
- usage_percent
- container_id
- docker_container_net
- tags:
- engine_host
- server_version
- container_image
- container_name
- container_status
- container_version
- network
- fields:
- rx_dropped
- rx_bytes
- rx_errors
- tx_packets
- tx_dropped
- rx_packets
- tx_errors
- tx_bytes
- container_id
- docker_container_blkio
- tags:
- engine_host
- server_version
- container_image
- container_name
- container_status
- container_version
- device
- fields:
- io_service_bytes_recursive_async
- io_service_bytes_recursive_read
- io_service_bytes_recursive_sync
- io_service_bytes_recursive_total
- io_service_bytes_recursive_write
- io_serviced_recursive_async
- io_serviced_recursive_read
- io_serviced_recursive_sync
- io_serviced_recursive_total
- io_serviced_recursive_write
- container_id
The `docker_container_health` measurements report on a containers
[HEALTHCHECK](https://docs.docker.com/engine/reference/builder/#healthcheck)
status if configured.
- docker_container_health (container must use the HEALTHCHECK)
- tags:
- engine_host
- server_version
- container_image
- container_name
- container_status
- container_version
- fields:
- health_status (string)
- failing_streak (integer)
- docker_container_status
- tags:
- engine_host
- server_version
- container_image
- container_name
- container_status
- container_version
- fields:
- container_id
- oomkilled (boolean)
- pid (integer)
- exitcode (integer)
- started_at (integer)
- finished_at (integer)
- uptime_ns (integer)
- docker_swarm
- tags:
- service_id
- service_name
- service_mode
- fields:
- tasks_desired
- tasks_running
- docker_disk_usage
- tags:
- engine_host
- server_version
- container_name
- container_image
- container_version
- image_id
- image_name
- image_version
- volume_name
- fields:
- size_rw
- size_root_fs
- size
- shared_size
## Example Output
```text
docker,engine_host=debian-stretch-docker,server_version=17.09.0-ce n_containers=6i,n_containers_paused=0i,n_containers_running=1i,n_containers_stopped=5i,n_cpus=2i,n_goroutines=41i,n_images=2i,n_listener_events=0i,n_used_file_descriptors=27i 1524002041000000000
docker,engine_host=debian-stretch-docker,server_version=17.09.0-ce,unit=bytes memory_total=2101661696i 1524002041000000000
docker_container_mem,container_image=telegraf,container_name=zen_ritchie,container_status=running,container_version=unknown,engine_host=debian-stretch-docker,server_version=17.09.0-ce active_anon=8327168i,active_file=2314240i,cache=27402240i,container_id="adc4ba9593871bf2ab95f3ffde70d1b638b897bb225d21c2c9c84226a10a8cf4",hierarchical_memory_limit=9223372036854771712i,inactive_anon=0i,inactive_file=25088000i,limit=2101661696i,mapped_file=20582400i,max_usage=36646912i,pgfault=4193i,pgmajfault=214i,pgpgin=9243i,pgpgout=520i,rss=8327168i,rss_huge=0i,total_active_anon=8327168i,total_active_file=2314240i,total_cache=27402240i,total_inactive_anon=0i,total_inactive_file=25088000i,total_mapped_file=20582400i,total_pgfault=4193i,total_pgmajfault=214i,total_pgpgin=9243i,total_pgpgout=520i,total_rss=8327168i,total_rss_huge=0i,total_unevictable=0i,total_writeback=0i,unevictable=0i,usage=36528128i,usage_percent=0.4342225020025297,writeback=0i 1524002042000000000
docker_container_cpu,container_image=telegraf,container_name=zen_ritchie,container_status=running,container_version=unknown,cpu=cpu-total,engine_host=debian-stretch-docker,server_version=17.09.0-ce container_id="adc4ba9593871bf2ab95f3ffde70d1b638b897bb225d21c2c9c84226a10a8cf4",throttling_periods=0i,throttling_throttled_periods=0i,throttling_throttled_time=0i,usage_in_kernelmode=40000000i,usage_in_usermode=100000000i,usage_percent=0,usage_system=6394210000000i,usage_total=117319068i 1524002042000000000
docker_container_cpu,container_image=telegraf,container_name=zen_ritchie,container_status=running,container_version=unknown,cpu=cpu0,engine_host=debian-stretch-docker,server_version=17.09.0-ce container_id="adc4ba9593871bf2ab95f3ffde70d1b638b897bb225d21c2c9c84226a10a8cf4",usage_total=20825265i 1524002042000000000
docker_container_cpu,container_image=telegraf,container_name=zen_ritchie,container_status=running,container_version=unknown,cpu=cpu1,engine_host=debian-stretch-docker,server_version=17.09.0-ce container_id="adc4ba9593871bf2ab95f3ffde70d1b638b897bb225d21c2c9c84226a10a8cf4",usage_total=96493803i 1524002042000000000
docker_container_net,container_image=telegraf,container_name=zen_ritchie,container_status=running,container_version=unknown,engine_host=debian-stretch-docker,network=eth0,server_version=17.09.0-ce container_id="adc4ba9593871bf2ab95f3ffde70d1b638b897bb225d21c2c9c84226a10a8cf4",rx_bytes=1576i,rx_dropped=0i,rx_errors=0i,rx_packets=20i,tx_bytes=0i,tx_dropped=0i,tx_errors=0i,tx_packets=0i 1524002042000000000
docker_container_blkio,container_image=telegraf,container_name=zen_ritchie,container_status=running,container_version=unknown,device=254:0,engine_host=debian-stretch-docker,server_version=17.09.0-ce container_id="adc4ba9593871bf2ab95f3ffde70d1b638b897bb225d21c2c9c84226a10a8cf4",io_service_bytes_recursive_async=27398144i,io_service_bytes_recursive_read=27398144i,io_service_bytes_recursive_sync=0i,io_service_bytes_recursive_total=27398144i,io_service_bytes_recursive_write=0i,io_serviced_recursive_async=529i,io_serviced_recursive_read=529i,io_serviced_recursive_sync=0i,io_serviced_recursive_total=529i,io_serviced_recursive_write=0i 1524002042000000000
docker_container_health,container_image=telegraf,container_name=zen_ritchie,container_status=running,container_version=unknown,engine_host=debian-stretch-docker,server_version=17.09.0-ce failing_streak=0i,health_status="healthy" 1524007529000000000
docker_swarm,service_id=xaup2o9krw36j2dy1mjx1arjw,service_mode=replicated,service_name=test tasks_desired=3,tasks_running=3 1508968160000000000
docker_disk_usage,engine_host=docker-desktop,server_version=24.0.5 layers_size=17654519107i 1695742041000000000
docker_disk_usage,container_image=influxdb,container_name=frosty_wright,container_version=1.8,engine_host=docker-desktop,server_version=24.0.5 size_root_fs=286593526i,size_rw=538i 1695742041000000000
docker_disk_usage,engine_host=docker-desktop,image_id=7f4a1cc74046,image_name=telegraf,image_version=latest,server_version=24.0.5 shared_size=0i,size=425484494i 1695742041000000000
docker_disk_usage,engine_host=docker-desktop,server_version=24.0.5,volume_name=docker_influxdb-data size=91989940i 1695742041000000000
```

View file

@ -0,0 +1,120 @@
package docker
import (
"context"
"crypto/tls"
"net/http"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/client"
)
var (
defaultHeaders = map[string]string{"User-Agent": "engine-api-cli-1.0"}
)
type dockerClient interface {
// Info retrieves system-wide information about the Docker server.
Info(ctx context.Context) (system.Info, error)
// ContainerList retrieves a list of containers based on the specified options.
ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error)
// ContainerStats retrieves real-time statistics for a specific container.
ContainerStats(ctx context.Context, containerID string, stream bool) (container.StatsResponseReader, error)
// ContainerInspect retrieves detailed information about a specific container.
ContainerInspect(ctx context.Context, containerID string) (container.InspectResponse, error)
// ServiceList retrieves a list of services based on the specified options.
ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
// TaskList retrieves a list of tasks based on the specified options.
TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
// NodeList retrieves a list of nodes based on the specified options.
NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
// DiskUsage retrieves disk usage information.
DiskUsage(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error)
// ClientVersion retrieves the version of the Docker client.
ClientVersion() string
// Close releases any resources held by the client.
Close() error
}
func newEnvClient() (dockerClient, error) {
dockerClient, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return nil, err
}
return &socketClient{dockerClient}, nil
}
func newClient(host string, tlsConfig *tls.Config) (dockerClient, error) {
transport := &http.Transport{
TLSClientConfig: tlsConfig,
}
httpClient := &http.Client{Transport: transport}
dockerClient, err := client.NewClientWithOpts(
client.WithHTTPHeaders(defaultHeaders),
client.WithHTTPClient(httpClient),
client.WithAPIVersionNegotiation(),
client.WithHost(host))
if err != nil {
return nil, err
}
return &socketClient{dockerClient}, nil
}
type socketClient struct {
client *client.Client
}
// Info retrieves system-wide information about the Docker server.
func (c *socketClient) Info(ctx context.Context) (system.Info, error) {
return c.client.Info(ctx)
}
// ContainerList retrieves a list of containers based on the specified options.
func (c *socketClient) ContainerList(ctx context.Context, options container.ListOptions) ([]container.Summary, error) {
return c.client.ContainerList(ctx, options)
}
// ContainerStats retrieves real-time statistics for a specific container.
func (c *socketClient) ContainerStats(ctx context.Context, containerID string, stream bool) (container.StatsResponseReader, error) {
return c.client.ContainerStats(ctx, containerID, stream)
}
// ContainerInspect retrieves detailed information about a specific container.
func (c *socketClient) ContainerInspect(ctx context.Context, containerID string) (container.InspectResponse, error) {
return c.client.ContainerInspect(ctx, containerID)
}
// ServiceList retrieves a list of services based on the specified options.
func (c *socketClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) {
return c.client.ServiceList(ctx, options)
}
// TaskList retrieves a list of tasks based on the specified options.
func (c *socketClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) {
return c.client.TaskList(ctx, options)
}
// NodeList retrieves a list of nodes based on the specified options.
func (c *socketClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) {
return c.client.NodeList(ctx, options)
}
// DiskUsage retrieves disk usage information.
func (c *socketClient) DiskUsage(ctx context.Context, options types.DiskUsageOptions) (types.DiskUsage, error) {
return c.client.DiskUsage(ctx, options)
}
// ClientVersion retrieves the version of the Docker client.
func (c *socketClient) ClientVersion() string {
return c.client.ClientVersion()
}
// Close releases any resources held by the client.
func (c *socketClient) Close() error {
return c.client.Close()
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,586 @@
package docker
import (
"fmt"
"io"
"strings"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/api/types/volume"
)
var info = system.Info{
Containers: 108,
ContainersRunning: 98,
ContainersStopped: 6,
ContainersPaused: 3,
OomKillDisable: false,
SystemTime: "2016-02-24T00:55:09.15073105-05:00",
NEventsListener: 0,
ID: "5WQQ:TFWR:FDNG:OKQ3:37Y4:FJWG:QIKK:623T:R3ME:QTKB:A7F7:OLHD",
Debug: false,
LoggingDriver: "json-file",
KernelVersion: "4.3.0-1-amd64",
IndexServerAddress: "https://index.docker.io/v1/",
MemTotal: 3840757760,
Images: 199,
CPUCfsQuota: true,
Name: "absol",
SwapLimit: false,
IPv4Forwarding: true,
ExperimentalBuild: false,
CPUCfsPeriod: true,
RegistryConfig: &registry.ServiceConfig{
IndexConfigs: map[string]*registry.IndexInfo{
"docker.io": {
Name: "docker.io",
Mirrors: make([]string, 0),
Official: true,
Secure: true,
},
}, InsecureRegistryCIDRs: []*registry.NetIPNet{{IP: []byte{127, 0, 0, 0}, Mask: []byte{255, 0, 0, 0}}}, Mirrors: make([]string, 0)},
OperatingSystem: "Linux Mint LMDE (containerized)",
BridgeNfIptables: true,
HTTPSProxy: "",
Labels: make([]string, 0),
MemoryLimit: false,
DriverStatus: [][2]string{
{"Pool Name", "docker-8:1-1182287-pool"},
{"Base Device Size", "10.74 GB"},
{"Pool Blocksize", "65.54 kB"},
{"Backing Filesystem", "extfs"},
{"Data file", "/dev/loop0"},
{"Metadata file", "/dev/loop1"},
{"Data Space Used", "17.3 GB"},
{"Data Space Total", "107.4 GB"},
{"Data Space Available", "36.53 GB"},
{"Metadata Space Used", "20.97 MB"},
{"Metadata Space Total", "2.147 GB"},
{"Metadata Space Available", "2.127 GB"},
{"Udev Sync Supported", "true"},
{"Deferred Removal Enabled", "false"},
{"Data loop file", "/var/lib/docker/devicemapper/devicemapper/data"},
{"Metadata loop file", "/var/lib/docker/devicemapper/devicemapper/metadata"},
{"Library Version", "1.02.115 (2016-01-25)"},
{"Thin Pool Minimum Free Space", "10.74GB"},
},
NFd: 19,
HTTPProxy: "",
Driver: "devicemapper",
NGoroutines: 39,
NCPU: 4,
DockerRootDir: "/var/lib/docker",
NoProxy: "",
BridgeNfIP6tables: true,
ServerVersion: "17.09.0-ce",
}
var containerList = []container.Summary{
{
ID: "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb",
Names: []string{"/etcd"},
Image: "quay.io/coreos/etcd:v3.3.25",
Command: "/etcd -name etcd0 -advertise-client-urls http://localhost:2379 -listen-client-urls http://0.0.0.0:2379",
Created: 1455941930,
Status: "Up 4 hours",
Ports: []container.Port{
{
PrivatePort: 7001,
PublicPort: 0,
Type: "tcp",
},
{
PrivatePort: 4001,
PublicPort: 0,
Type: "tcp",
},
{
PrivatePort: 2380,
PublicPort: 0,
Type: "tcp",
},
{
PrivatePort: 2379,
PublicPort: 2379,
Type: "tcp",
IP: "0.0.0.0",
},
},
Labels: map[string]string{
"label1": "test_value_1",
"label2": "test_value_2",
},
SizeRw: 0,
SizeRootFs: 0,
},
{
ID: "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173",
Names: []string{"/etcd2"},
Image: "quay.io:4443/coreos/etcd:v3.3.25",
Command: "/etcd -name etcd2 -advertise-client-urls http://localhost:2379 -listen-client-urls http://0.0.0.0:2379",
Created: 1455941933,
Status: "Up 4 hours",
Ports: []container.Port{
{
PrivatePort: 7002,
PublicPort: 0,
Type: "tcp",
},
{
PrivatePort: 4002,
PublicPort: 0,
Type: "tcp",
},
{
PrivatePort: 2381,
PublicPort: 0,
Type: "tcp",
},
{
PrivatePort: 2382,
PublicPort: 2382,
Type: "tcp",
IP: "0.0.0.0",
},
},
Labels: map[string]string{
"label1": "test_value_1",
"label2": "test_value_2",
},
SizeRw: 0,
SizeRootFs: 0,
},
{
ID: "e8a713dd90604f5a257b97c15945e047ab60ed5b2c4397c5a6b5bf40e1bd2791",
Names: []string{"/acme"},
},
{
ID: "9bc6faf9ba8106fae32e8faafd38a1dd6f6d262bec172398cc10bc03c0d6841a",
Names: []string{"/acme-test"},
},
{
ID: "d4ccced494a1d5fe8ebdb0a86335a0dab069319912221e5838a132ab18a8bc84",
Names: []string{"/foo"},
},
}
var two = uint64(2)
var serviceList = []swarm.Service{
{
ID: "qolkls9g5iasdiuihcyz9rnx2",
Spec: swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: "test1",
},
Mode: swarm.ServiceMode{
Replicated: &swarm.ReplicatedService{
Replicas: &two,
},
},
},
},
{
ID: "qolkls9g5iasdiuihcyz9rn3",
Spec: swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: "test2",
},
Mode: swarm.ServiceMode{
Global: &swarm.GlobalService{},
},
},
},
{
ID: "rfmqydhe8cluzl9hayyrhw5ga",
Spec: swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: "test3",
},
Mode: swarm.ServiceMode{
ReplicatedJob: &swarm.ReplicatedJob{
MaxConcurrent: &two,
TotalCompletions: &two,
},
},
},
},
{
ID: "mp50lo68vqgkory4e26ts8f9d",
Spec: swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: "test4",
},
Mode: swarm.ServiceMode{
GlobalJob: &swarm.GlobalJob{},
},
},
},
}
var taskList = []swarm.Task{
{
ID: "kwh0lv7hwwbh",
ServiceID: "qolkls9g5iasdiuihcyz9rnx2",
NodeID: "0cl4jturcyd1ks3fwpd010kor",
Status: swarm.TaskStatus{
State: "running",
},
DesiredState: "running",
},
{
ID: "u78m5ojbivc3",
ServiceID: "qolkls9g5iasdiuihcyz9rnx2",
NodeID: "0cl4jturcyd1ks3fwpd010kor",
Status: swarm.TaskStatus{
State: "running",
},
DesiredState: "running",
},
{
ID: "1n1uilkhr98l",
ServiceID: "qolkls9g5iasdiuihcyz9rn3",
NodeID: "0cl4jturcyd1ks3fwpd010kor",
Status: swarm.TaskStatus{
State: "running",
},
DesiredState: "running",
},
}
var nodeList = []swarm.Node{
{
ID: "0cl4jturcyd1ks3fwpd010kor",
Status: swarm.NodeStatus{
State: "ready",
},
},
{
ID: "0cl4jturcyd1ks3fwpd010kor",
Status: swarm.NodeStatus{
State: "ready",
},
},
}
func containerStats(s string) container.StatsResponseReader {
var stat container.StatsResponseReader
var name string
switch s {
case "e2173b9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296b7dfb":
name = "etcd"
case "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173":
name = "etcd2"
case "e8a713dd90604f5a257b97c15945e047ab60ed5b2c4397c5a6b5bf40e1bd2791":
name = "/acme"
case "9bc6faf9ba8106fae32e8faafd38a1dd6f6d262bec172398cc10bc03c0d6841a":
name = "/acme-test"
case "d4ccced494a1d5fe8ebdb0a86335a0dab069319912221e5838a132ab18a8bc84":
name = "/foo"
}
jsonStat := fmt.Sprintf(`
{
"name": "%s",
"blkio_stats": {
"io_service_bytes_recursive": [
{
"major": 252,
"minor": 1,
"op": "Read",
"value": 753664
},
{
"major": 252,
"minor": 1,
"op": "Write"
},
{
"major": 252,
"minor": 1,
"op": "Sync"
},
{
"major": 252,
"minor": 1,
"op": "Async",
"value": 753664
},
{
"major": 252,
"minor": 1,
"op": "Total",
"value": 753664
}
],
"io_serviced_recursive": [
{
"major": 252,
"minor": 1,
"op": "Read",
"value": 26
},
{
"major": 252,
"minor": 1,
"op": "Write"
},
{
"major": 252,
"minor": 1,
"op": "Sync"
},
{
"major": 252,
"minor": 1,
"op": "Async",
"value": 26
},
{
"major": 252,
"minor": 1,
"op": "Total",
"value": 26
}
]
},
"cpu_stats": {
"cpu_usage": {
"percpu_usage": [
17871,
4959158,
1646137,
1231652,
11829401,
244656,
369972,
0
],
"total_usage": 20298847,
"usage_in_usermode": 10000000
},
"system_cpu_usage": 24052607520000000,
"throttling_data": {}
},
"memory_stats": {
"limit": 18935443456,
"stats": {}
},
"precpu_stats": {
"cpu_usage": {
"percpu_usage": [
17871,
4959158,
1646137,
1231652,
11829401,
244656,
369972,
0
],
"total_usage": 20298847,
"usage_in_usermode": 10000000
},
"system_cpu_usage": 24052599550000000,
"throttling_data": {}
},
"read": "2016-02-24T11:42:27.472459608-05:00"
}`, name)
stat.Body = io.NopCloser(strings.NewReader(jsonStat))
return stat
}
func testStats() *container.StatsResponse {
stats := &container.StatsResponse{}
stats.Read = time.Now()
stats.Networks = make(map[string]container.NetworkStats)
stats.CPUStats.OnlineCPUs = 2
stats.CPUStats.CPUUsage.PercpuUsage = []uint64{1, 1002, 0, 0}
stats.CPUStats.CPUUsage.UsageInUsermode = 100
stats.CPUStats.CPUUsage.TotalUsage = 500
stats.CPUStats.CPUUsage.UsageInKernelmode = 200
stats.CPUStats.SystemUsage = 100
stats.CPUStats.ThrottlingData.Periods = 1
stats.PreCPUStats.CPUUsage.TotalUsage = 400
stats.PreCPUStats.SystemUsage = 50
stats.MemoryStats.Stats = make(map[string]uint64)
stats.MemoryStats.Stats["active_anon"] = 0
stats.MemoryStats.Stats["active_file"] = 1
stats.MemoryStats.Stats["cache"] = 0
stats.MemoryStats.Stats["hierarchical_memory_limit"] = 0
stats.MemoryStats.Stats["inactive_anon"] = 0
stats.MemoryStats.Stats["inactive_file"] = 3
stats.MemoryStats.Stats["mapped_file"] = 0
stats.MemoryStats.Stats["pgfault"] = 2
stats.MemoryStats.Stats["pgmajfault"] = 0
stats.MemoryStats.Stats["pgpgin"] = 0
stats.MemoryStats.Stats["pgpgout"] = 0
stats.MemoryStats.Stats["rss"] = 0
stats.MemoryStats.Stats["rss_huge"] = 0
stats.MemoryStats.Stats["total_active_anon"] = 0
stats.MemoryStats.Stats["total_active_file"] = 0
stats.MemoryStats.Stats["total_cache"] = 0
stats.MemoryStats.Stats["total_inactive_anon"] = 0
stats.MemoryStats.Stats["total_inactive_file"] = 0
stats.MemoryStats.Stats["total_mapped_file"] = 0
stats.MemoryStats.Stats["total_pgfault"] = 0
stats.MemoryStats.Stats["total_pgmajfault"] = 0
stats.MemoryStats.Stats["total_pgpgin"] = 4
stats.MemoryStats.Stats["total_pgpgout"] = 0
stats.MemoryStats.Stats["total_rss"] = 44
stats.MemoryStats.Stats["total_rss_huge"] = 444
stats.MemoryStats.Stats["total_unevictable"] = 0
stats.MemoryStats.Stats["total_writeback"] = 55
stats.MemoryStats.Stats["unevictable"] = 0
stats.MemoryStats.Stats["writeback"] = 0
stats.MemoryStats.MaxUsage = 1001
stats.MemoryStats.Usage = 1111
stats.MemoryStats.Failcnt = 1
stats.MemoryStats.Limit = 2000
stats.Networks["eth0"] = container.NetworkStats{
RxDropped: 1,
RxBytes: 2,
RxErrors: 3,
TxPackets: 4,
TxDropped: 1,
RxPackets: 2,
TxErrors: 3,
TxBytes: 4,
}
stats.Networks["eth1"] = container.NetworkStats{
RxDropped: 5,
RxBytes: 6,
RxErrors: 7,
TxPackets: 8,
TxDropped: 5,
RxPackets: 6,
TxErrors: 7,
TxBytes: 8,
}
sbr := container.BlkioStatEntry{
Major: 6,
Minor: 0,
Op: "read",
Value: 100,
}
sr := container.BlkioStatEntry{
Major: 6,
Minor: 0,
Op: "write",
Value: 101,
}
sr2 := container.BlkioStatEntry{
Major: 6,
Minor: 1,
Op: "write",
Value: 201,
}
stats.BlkioStats.IoServiceBytesRecursive = append(
stats.BlkioStats.IoServiceBytesRecursive, sbr)
stats.BlkioStats.IoServicedRecursive = append(
stats.BlkioStats.IoServicedRecursive, sr)
stats.BlkioStats.IoServicedRecursive = append(
stats.BlkioStats.IoServicedRecursive, sr2)
return stats
}
func containerStatsWindows() container.StatsResponseReader {
var stat container.StatsResponseReader
jsonStat := `
{
"read":"2017-01-11T08:32:46.2413794Z",
"preread":"0001-01-01T00:00:00Z",
"num_procs":64,
"cpu_stats":{
"cpu_usage":{
"total_usage":536718750,
"usage_in_kernelmode":390468750,
"usage_in_usermode":390468750
},
"throttling_data":{
"periods":0,
"throttled_periods":0,
"throttled_time":0
}
},
"precpu_stats":{
"cpu_usage":{
"total_usage":0,
"usage_in_kernelmode":0,
"usage_in_usermode":0
},
"throttling_data":{
"periods":0,
"throttled_periods":0,
"throttled_time":0
}
},
"memory_stats":{
"commitbytes":77160448,
"commitpeakbytes":105000960,
"privateworkingset":59961344
},
"name":"/gt_test_iis",
}`
stat.Body = io.NopCloser(strings.NewReader(jsonStat))
return stat
}
func containerInspect() container.InspectResponse {
return container.InspectResponse{
Config: &container.Config{
Env: []string{
"ENVVAR1=loremipsum",
"ENVVAR1FOO=loremipsum",
"ENVVAR2=dolorsitamet",
"ENVVAR3==ubuntu:10.04",
"ENVVAR4",
"ENVVAR5=",
"ENVVAR6= ",
"ENVVAR7=ENVVAR8=ENVVAR9",
"PATH=/bin:/sbin",
},
},
ContainerJSONBase: &container.ContainerJSONBase{
State: &container.State{
Health: &container.Health{
FailingStreak: 1,
Status: "Unhealthy",
},
Status: "running",
OOMKilled: false,
Pid: 1234,
ExitCode: 0,
StartedAt: "2018-06-14T05:48:53.266176036Z",
FinishedAt: "0001-01-01T00:00:00Z",
},
},
}
}
var diskUsage = types.DiskUsage{
LayersSize: 1e10,
Containers: []*container.Summary{
{Names: []string{"/some_container"}, Image: "some_image:1.0.0-alpine", SizeRw: 0, SizeRootFs: 123456789},
},
Images: []*image.Summary{
{ID: "sha256:some_imageid", RepoTags: []string{"some_image_tag:1.0.0-alpine"}, Size: 123456789, SharedSize: 0},
{ID: "sha256:7f4a1cc74046ce48cd918693cd6bf4b2683f4ce0d7be3f7148a21df9f06f5b5f", RepoTags: []string{"telegraf:latest"}, Size: 425484494, SharedSize: 0},
},
Volumes: []*volume.Volume{{Name: "some_volume", UsageData: &volume.UsageData{Size: 123456789}}},
}
var version = "1.43"

View file

@ -0,0 +1,11 @@
package docker
import "errors"
var (
errInfoTimeout = errors.New("timeout retrieving docker engine info")
errStatsTimeout = errors.New("timeout retrieving container stats")
errInspectTimeout = errors.New("timeout retrieving container environment")
errListTimeout = errors.New("timeout retrieving container list")
errServiceTimeout = errors.New("timeout retrieving swarm service list")
)

View file

@ -0,0 +1,64 @@
# Read metrics about docker containers
[[inputs.docker]]
## 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"
## Set to true to collect Swarm metrics(desired_replicas, running_replicas)
## Note: configure this in one of the manager nodes in a Swarm cluster.
## configuring in multiple Swarm managers results in duplication of metrics.
gather_services = false
## Only collect metrics for these containers. Values will be appended to
## container_name_include.
## Deprecated (1.4.0), use container_name_include
container_names = []
## Set the source tag for the metrics to the container ID hostname, eg first 12 chars
source_tag = false
## Containers to include and exclude. Collect all if empty. Globs accepted.
container_name_include = []
container_name_exclude = []
## Container states to include and exclude. Globs accepted.
## When empty only containers in the "running" state will be captured.
## example: container_state_include = ["created", "restarting", "running", "removing", "paused", "exited", "dead"]
## example: container_state_exclude = ["created", "restarting", "running", "removing", "paused", "exited", "dead"]
# container_state_include = []
# container_state_exclude = []
## Objects to include for disk usage query
## Allowed values are "container", "image", "volume"
## When empty disk usage is excluded
storage_objects = []
## Timeout for docker list, info, and stats commands
timeout = "5s"
## Specifies for which classes a per-device metric should be issued
## Possible values are 'cpu' (cpu0, cpu1, ...), 'blkio' (8:0, 8:1, ...) and 'network' (eth0, eth1, ...)
## Please note that this setting has no effect if 'perdevice' is set to 'true'
# perdevice_include = ["cpu"]
## Specifies for which classes a total metric should be issued. Total is an aggregated of the 'perdevice' values.
## Possible values are 'cpu', 'blkio' and 'network'
## Total 'cpu' is reported directly by Docker daemon, and 'network' and 'blkio' totals are aggregated by this plugin.
## Please note that this setting has no effect if 'total' is set to 'false'
# total_include = ["cpu", "blkio", "network"]
## docker labels to include and exclude as tags. Globs accepted.
## Note that an empty array for both will include all labels as tags
docker_label_include = []
docker_label_exclude = []
## Which environment variables should we use as a tag
tag_env = ["JAVA_HOME", "HEAP_SIZE"]
## Optional TLS Config
# tls_ca = "/etc/telegraf/ca.pem"
# tls_cert = "/etc/telegraf/cert.pem"
# tls_key = "/etc/telegraf/key.pem"
## Use TLS but skip chain & host verification
# insecure_skip_verify = false