Monitor Docker containers
Collect per-container CPU, memory, network, and state metrics from the Docker daemon and write them to InfluxDB 3.
Configuration
[[inputs.docker]]
## Connect to the local Docker daemon socket.
endpoint = "unix:///var/run/docker.sock"
## Collect from running containers only.
container_state_include = ["running"]
## Report total container CPU instead of one metric per core.
perdevice_include = []
total_include = ["cpu", "blkio", "network"]
## Keep only the compose service label as a tag.
docker_label_include = ["com.docker.compose.service"]
[[outputs.influxdb_v3]]
urls = ["http://localhost:8181"]
token = "AUTH_TOKEN"
database = "DATABASE_NAME"Replace the following:
AUTH_TOKEN: your InfluxDB authorization tokenDATABASE_NAME: the database to write to
Where to run Telegraf
Telegraf can monitor Docker from the host or from a container of its own.
Either way, the Telegraf process must be able to reach the Docker daemon
socket that endpoint points to.
On the host: add the telegraf user to the docker group so it can
read the socket, then restart Telegraf:
sudo usermod -aG docker telegrafIn a container: use the official telegraf image and bind-mount the Docker socket and your configuration file:
docker run --detach --name telegraf \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume $PWD/telegraf.conf:/etc/telegraf/telegraf.conf:ro \
telegrafMounting the Docker socket grants the container control over the Docker daemon. Only do this with images you trust.
How it works
endpointconnects to the Docker daemon through its Unix socket. Usetcp://<host>:<port>for a remote daemon, with the TLS options as needed.container_state_includeskips created, exited, and paused containers, so you only pay for containers doing work.perdevice_includeandtotal_includecontrol metric granularity. This example reports accumulated totals per container instead of one metric per CPU core, block device, and interface, which keeps series counts low.docker_label_includelimits which container labels become tags. Container labels are often high-cardinality. Allowlist only the labels you query by.- The plugin also produces
dockeranddocker_datasummary metrics for the engine itself, such as container counts and storage usage.
Example output
docker,engine_host=host1,server_version=27.0.3 n_containers=12i,n_containers_running=8i,n_images=41i 1709572230000000000
docker_container_cpu,com.docker.compose.service=api,container_image=example/api,container_name=api-1,container_version=1.4.2,cpu=cpu-total usage_percent=12.7 1709572230000000000
docker_container_mem,com.docker.compose.service=api,container_image=example/api,container_name=api-1,container_version=1.4.2 usage_percent=23.1,usage=498073600i,limit=2147483648i 1709572230000000000
docker_container_net,com.docker.compose.service=api,container_image=example/api,container_name=api-1,container_version=1.4.2,network=total rx_bytes=87234981i,tx_bytes=12873411i 1709572230000000000Extend this example
- Scope collection with
container_name_includeor metric filters when you only care about specific services. - Add inputs.docker_log to collect container logs through the same daemon connection.
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for Telegraf and this documentation. To find support, use the following resources:
Customers with an annual or support contract can contact InfluxData Support.