plugins/inputs/docker/README.md
This plugin uses the Docker Engine API to gather metrics on running Docker containers.
[!NOTE] Make sure Telegraf has sufficient permissions to access the configured endpoint.
⭐ Telegraf v0.1.9 🏷️ containers 💻 all
Plugins support additional global and plugin configuration settings for tasks such as modifying metrics, tags, and fields, creating aliases, and configuring plugin ordering. See CONFIGURATION.md for more details.
# Read metrics about docker containers
[[inputs.docker]]
## Endpoint, either "tcp://[ip]:[port]" for TCP, "unix:///<path>" for socket
## or "ENV" for using environment variables (i.e., docker-machine)
# endpoint = "unix:///var/run/docker.sock"
## Collect Swarm metrics (desired_replicas, running_replicas)
## Note: Configure this for one of the manager nodes in a Swarm cluster only
## as you will see duplicate metrics otherwise.
# gather_services = false
## Use container ID hostname as source (trimmed to 12 characters)
# source_tag = false
## Containers to include and exclude accepting wildcards; all if empty
# container_name_include = []
# container_name_exclude = []
## Container states to include and exclude accepting wildcards; available:
## "created", "restarting", "running", "removing", "paused", "exited", "dead"
# container_state_include = ["running"]
# container_state_exclude = []
## Objects to include for disk usage query; available:
## "container", "image", "volume"
# storage_objects = []
## Timeout for docker list, info, and stats commands
# timeout = "5s"
## Podman compatibility settings (auto-enabled when Podman detected)
## Cache TTL for accurate CPU percentage calculation. Should be higher than
## your collection interval for accurate measurements. Zero will keep cache
## entries forever (not recommended for dynamic environments).
# podman_cache_ttl = "60s"
## Emit per-device metric for the given classes; available:
## 'cpu' (cpu0, ...), 'blkio' (8:0, ...) and 'network' (eth0, ...)
# perdevice_include = ["cpu"]
## Emit accumulated metrics for the given classes; available:
## 'cpu', 'blkio' and 'network'
# total_include = ["cpu", "blkio", "network"]
## Container labels to include as tags accepting wildcards; all if empty
# docker_label_include = []
# docker_label_exclude = []
## Which environment variables should we use as a tag
## e.g. tag_env = ["JAVA_HOME", "HEAP_SIZE"]
# tag_env = []
## 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
When using the "ENV" endpoint, the connection is configured using the cli
Docker environment variables.
Giving telegraf access to the Docker daemon expands the 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.
This plugin is compatible with Podman through its Docker-compatible API. When connected to Podman:
endpoint = "unix:///run/podman/podman.sock"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:
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:
user: telegraf:<host_docker_gid>
volumes:
- /var/run/docker.sock:/var/run/docker.sock
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
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 may add many labels to your containers, if they are not needed you may prefer to exclude them:
docker_label_exclude = ["annotation.kubernetes*"]
Docker-compose will add labels to your containers. You can limit restrict labels to selected ones, e.g.
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",
]
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)
docker_metadata (deprecated see: docker_devicemapper)
The above measurements for the devicemapper storage driver can now be found in
the new docker_devicemapper measurement
docker_devicemapper
docker_container_mem
docker_container_cpu
docker_container_net
docker_container_blkio
The docker_container_health measurements report on a containers
HEALTHCHECK
status if configured.
docker_container_health (container must use the HEALTHCHECK)
docker_container_status
docker_swarm
docker_disk_usage
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