2016-01-21 07:21:19 +08:00
# Docker Input Plugin
2017-07-28 08:18:44 +08:00
The docker plugin uses the Docker Engine API to gather metrics on running
docker containers.
2016-01-21 07:21:19 +08:00
2017-07-28 08:18:44 +08:00
The docker plugin uses the [Official Docker Client ](https://github.com/moby/moby/tree/master/client )
2018-04-24 06:09:04 +08:00
to gather stats from the [Engine API ](https://docs.docker.com/engine/api/v1.24/ ).
2016-01-21 07:21:19 +08:00
2021-11-25 02:56:26 +08:00
## Configuration
2016-01-21 07:21:19 +08:00
2018-04-24 06:09:04 +08:00
```toml
2016-01-21 07:21:19 +08:00
# Read metrics about docker containers
[[inputs.docker]]
2017-02-18 03:36:44 +08:00
## Docker Endpoint
## To use TCP, set endpoint = "tcp://[ip]:[port]"
## To use environment variables (ie, docker-machine), set endpoint = "ENV"
2016-01-21 07:21:19 +08:00
endpoint = "unix:///var/run/docker.sock"
2017-06-09 04:17:31 +08:00
2017-10-31 03:26:39 +08:00
## 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
2017-07-28 06:12:29 +08:00
## Only collect metrics for these containers. Values will be appended to
## container_name_include.
2017-06-09 04:17:31 +08:00
## Deprecated (1.4.0), use container_name_include
2016-01-21 07:21:19 +08:00
container_names = []
2017-06-09 04:17:31 +08:00
2019-10-08 08:27:32 +08:00
## Set the source tag for the metrics to the container ID hostname, eg first 12 chars
source_tag = false
2017-06-09 04:17:31 +08:00
## Containers to include and exclude. Collect all if empty. Globs accepted.
container_name_include = []
container_name_exclude = []
2018-03-31 04:17:48 +08:00
## Container states to include and exclude. Globs accepted.
## When empty only containers in the "running" state will be captured.
2019-07-16 08:10:42 +08:00
## example: container_state_include = ["created", "restarting", "running", "removing", "paused", "exited", "dead"]
## example: container_state_exclude = ["created", "restarting", "running", "removing", "paused", "exited", "dead"]
2018-03-31 04:17:48 +08:00
# container_state_include = []
# container_state_exclude = []
2017-02-18 03:36:44 +08:00
## Timeout for docker list, info, and stats commands
timeout = "5s"
2021-03-04 03:02:04 +08:00
## Whether to report for each container per-device blkio (8:0, 8:1...),
## network (eth0, eth1, ...) and cpu (cpu0, cpu1, ...) stats or not.
## Usage of this setting is discouraged since it will be deprecated in favor of 'perdevice_include'.
2021-11-25 02:56:26 +08:00
## Default value is 'true' for backwards compatibility, please set it to 'false' so that 'perdevice_include' setting
2021-03-04 03:02:04 +08:00
## is honored.
2017-02-18 03:36:44 +08:00
perdevice = true
2021-11-25 02:56:26 +08:00
2021-03-04 03:02:04 +08:00
## 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"]
2021-11-25 02:56:26 +08:00
2021-03-04 03:02:04 +08:00
## Whether to report for each container total blkio and network stats or not.
## Usage of this setting is discouraged since it will be deprecated in favor of 'total_include'.
2021-11-25 02:56:26 +08:00
## Default value is 'false' for backwards compatibility, please set it to 'true' so that 'total_include' setting
2021-03-04 03:02:04 +08:00
## is honored.
2017-02-18 03:36:44 +08:00
total = false
2021-11-25 02:56:26 +08:00
2021-03-04 03:02:04 +08:00
## Specifies for which classes a total metric should be issued. Total is an aggregated of the 'perdevice' values.
2021-11-25 02:56:26 +08:00
## Possible values are 'cpu', 'blkio' and 'network'
2021-03-04 03:02:04 +08:00
## 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"]
2017-07-28 06:12:29 +08:00
2017-04-04 04:43:15 +08:00
## 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 = []
2017-07-28 08:18:44 +08:00
2017-05-19 07:58:34 +08:00
## Which environment variables should we use as a tag
tag_env = ["JAVA_HOME", "HEAP_SIZE"]
2017-07-28 06:12:29 +08:00
2018-05-05 07:33:23 +08:00
## 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
2017-07-28 06:12:29 +08:00
# insecure_skip_verify = false
2016-01-21 07:21:19 +08:00
```
2021-11-25 02:56:26 +08:00
### Environment Configuration
2017-07-28 08:18:44 +08:00
When using the `"ENV"` endpoint, the connection is configured using the
[cli Docker environment variables ](https://godoc.org/github.com/moby/moby/client#NewEnvClient ).
2021-11-25 02:56:26 +08:00
### Security
2018-09-22 03:39:37 +08:00
Giving telegraf access to the Docker daemon expands the [attack surface ](https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface ) 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.
2021-11-25 02:56:26 +08:00
### Docker Daemon Permissions
2018-09-22 03:39:37 +08:00
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:
2021-11-25 02:56:26 +08:00
```shell
2018-09-22 03:39:37 +08:00
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:
2021-11-25 02:56:26 +08:00
```yaml
2018-09-22 03:39:37 +08:00
volumes:
- /var/run/docker.sock:/var/run/docker.sock
```
2021-11-25 02:56:26 +08:00
### source tag
2019-10-08 08:27:32 +08:00
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.
2021-11-25 02:56:26 +08:00
### Kubernetes Labels
2017-09-30 05:07:19 +08:00
Kubernetes may add many labels to your containers, if they are not needed you
may prefer to exclude them:
2021-11-25 02:56:26 +08:00
```json
2017-09-30 05:07:19 +08:00
docker_label_exclude = ["annotation.kubernetes*"]
```
2021-11-25 02:56:26 +08:00
### Docker-compose Labels
2021-05-04 04:02:21 +08:00
2021-11-25 02:56:26 +08:00
Docker-compose will add labels to your containers. You can limit restrict labels to selected ones, e.g.
2021-05-04 04:02:21 +08:00
2021-11-25 02:56:26 +08:00
```json
2021-05-04 04:02:21 +08:00
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",
]
```
2021-11-25 02:56:26 +08:00
### Metrics
2016-01-21 07:21:19 +08:00
2018-04-24 06:09:04 +08:00
- docker
- tags:
- unit
- engine_host
- server_version
2021-11-25 02:56:26 +08:00
- fields:
2018-04-24 06:09:04 +08:00
- 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
2019-07-15 17:24:47 +08:00
- pool_blocksize (requires devicemapper storage driver) (deprecated see: `docker_devicemapper` )
2018-08-28 04:05:41 +08:00
The `docker_data` and `docker_metadata` measurements are available only for
some storage drivers such as devicemapper.
2018-04-24 06:09:04 +08:00
2021-11-25 02:56:26 +08:00
- docker_data (deprecated see: `docker_devicemapper` )
2018-04-24 06:09:04 +08:00
- tags:
- unit
- engine_host
- server_version
2021-11-25 02:56:26 +08:00
- fields:
2018-04-24 06:09:04 +08:00
- available
- total
- used
2019-07-15 17:24:47 +08:00
- docker_metadata (deprecated see: `docker_devicemapper` )
2018-04-24 06:09:04 +08:00
- tags:
- unit
- engine_host
- server_version
2021-11-25 02:56:26 +08:00
- fields:
2018-04-24 06:09:04 +08:00
- available
- total
- used
2016-01-21 07:21:19 +08:00
2019-07-15 17:24:47 +08:00
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
2021-11-25 02:56:26 +08:00
- fields:
2019-07-15 17:24:47 +08:00
- 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
2021-11-25 02:56:26 +08:00
- docker_container_mem
2018-04-24 06:09:04 +08:00
- tags:
- engine_host
- server_version
- container_image
- container_name
2018-06-19 06:38:21 +08:00
- container_status
2018-04-24 06:09:04 +08:00
- container_version
2021-11-25 02:56:26 +08:00
- fields:
2020-05-14 15:41:58 +08:00
- total_pgmajfault
2016-01-21 07:21:19 +08:00
- 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
2016-04-19 06:20:46 +08:00
- container_id
2018-04-24 06:09:04 +08:00
2016-04-19 06:20:46 +08:00
- docker_container_cpu
2018-04-24 06:09:04 +08:00
- tags:
- engine_host
- server_version
- container_image
- container_name
2018-06-19 06:38:21 +08:00
- container_status
2018-04-24 06:09:04 +08:00
- container_version
- cpu
2021-11-25 02:56:26 +08:00
- fields:
2016-01-21 07:21:19 +08:00
- throttling_periods
- throttling_throttled_periods
- throttling_throttled_time
- usage_in_kernelmode
- usage_in_usermode
- usage_system
- usage_total
2016-02-26 23:12:37 +08:00
- usage_percent
2016-04-19 06:20:46 +08:00
- container_id
2018-04-24 06:09:04 +08:00
2021-11-25 02:56:26 +08:00
- docker_container_net
2018-04-24 06:09:04 +08:00
- tags:
- engine_host
- server_version
- container_image
- container_name
2018-06-19 06:38:21 +08:00
- container_status
2018-04-24 06:09:04 +08:00
- container_version
- network
2021-11-25 02:56:26 +08:00
- fields:
2016-01-21 07:21:19 +08:00
- rx_dropped
- rx_bytes
- rx_errors
- tx_packets
- tx_dropped
- rx_packets
- tx_errors
- tx_bytes
2016-04-19 06:20:46 +08:00
- container_id
2018-04-24 06:09:04 +08:00
2016-04-19 06:20:46 +08:00
- docker_container_blkio
2018-04-24 06:09:04 +08:00
- tags:
- engine_host
- server_version
- container_image
- container_name
2018-06-19 06:38:21 +08:00
- container_status
2018-04-24 06:09:04 +08:00
- container_version
- device
- fields:
2016-01-21 07:21:19 +08:00
- 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
2016-05-04 20:17:23 +08:00
- container_id
2016-02-24 12:58:14 +08:00
2018-08-28 04:05:41 +08:00
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)
2018-04-24 06:09:04 +08:00
- tags:
2017-04-04 04:43:15 +08:00
- engine_host
2018-04-24 06:09:04 +08:00
- server_version
2016-04-19 06:20:46 +08:00
- container_image
- container_name
2018-06-19 06:38:21 +08:00
- container_status
2017-04-04 04:43:15 +08:00
- container_version
2018-04-24 06:09:04 +08:00
- fields:
2021-11-25 02:56:26 +08:00
- health_status (string)
- failing_streak (integer)
2018-04-24 06:09:04 +08:00
2018-06-19 06:38:21 +08:00
- docker_container_status
- tags:
- engine_host
- server_version
- container_image
- container_name
- container_status
- container_version
- fields:
2019-06-22 03:20:35 +08:00
- container_id
2018-06-19 06:38:21 +08:00
- oomkilled (boolean)
- pid (integer)
- exitcode (integer)
- started_at (integer)
- finished_at (integer)
2019-06-20 06:37:10 +08:00
- uptime_ns (integer)
2018-06-19 06:38:21 +08:00
2018-04-24 06:09:04 +08:00
- docker_swarm
- tags:
2017-10-31 03:26:39 +08:00
- service_id
- service_name
- service_mode
2018-04-24 06:09:04 +08:00
- fields:
- tasks_desired
- tasks_running
2016-01-21 07:21:19 +08:00
2021-11-25 02:56:26 +08:00
## Example
2016-01-21 07:21:19 +08:00
2021-11-25 02:56:26 +08:00
```shell
2018-04-24 06:09:04 +08:00
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
2018-06-19 06:38:21 +08:00
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
2018-04-24 06:09:04 +08:00
docker_swarm,service_id=xaup2o9krw36j2dy1mjx1arjw,service_mode=replicated,service_name=test tasks_desired=3,tasks_running=3 1508968160000000000
2018-01-13 09:43:51 +08:00
```