Docker
Monitor CPU, memory, network, and block I/O of Docker containers with the OpenTelemetry Collector Docker Stats receiver.
Overview
Docker runs applications in isolated containers that share the kernel of one host. Docker Compose and standalone Docker hosts run anything from a developer's local stack to production services on virtual machines and edge devices, often with several containers competing for the same CPU, memory, disk, and network.
When one container uses more than its share, the others slow down, and a container that reaches its memory limit is killed by the kernel. The OpenTelemetry Collector's Docker Stats receiver reads the Docker daemon's container stats API and reports CPU, memory, network, and block I/O metrics for every running container to Dash0, without an agent inside the containers. It also works with Podman through its Docker-compatible API.
Running containers on Kubernetes? Use the Kubernetes integration instead. It collects container metrics from the kubelet together with pod, node, and workload context.
Use Cases
- Monitor CPU and memory usage per container to find the containers that consume the most resources on a host.
- Detect containers that approach their memory limit before the kernel's out-of-memory killer stops them.
- Track network throughput and dropped packets per container to spot noisy neighbors and network problems.
- Analyze block I/O read and write rates to find containers that saturate the host's disks.
- Understand how CPU time splits between user mode and kernel mode to tell application work apart from system call and I/O overhead.
Setup
Overview
The OpenTelemetry Collector's Docker Stats receiver connects to the Docker daemon on the same host, through its Unix
socket, and requests the stats of every running container at a fixed interval. It converts the stats into metrics with
the container.* prefix and attaches the container's name, ID, image, and hostname as attributes. The collector then
forwards these metrics to Dash0.
With the default configuration, the receiver reports these metrics:
- CPU:
container.cpu.usage.total,container.cpu.usage.usermode,container.cpu.usage.kernelmode(cumulative CPU time in nanoseconds), andcontainer.cpu.utilization. - Memory:
container.memory.usage.total(excluding the page cache),container.memory.usage.limit, andcontainer.memory.percent(usage as a percentage of the limit). Depending on the cgroup version of the host, alsocontainer.memory.file(cgroup v2) orcontainer.memory.total_cache(cgroup v1). - Network:
container.network.io.usage.rx_bytes,container.network.io.usage.tx_bytes,container.network.io.usage.rx_dropped, andcontainer.network.io.usage.tx_dropped, per network interface. - Block I/O:
container.blockio.io_service_bytes_recursive, with theoperationattribute set toread,write, and other operations.
More metrics, such as container.uptime, container.restarts, container.pids.count, and per-CPU usage, are
available but disabled by default (see Enable Optional Metrics).
Prerequisites
Before setting up Docker monitoring, ensure:
- Docker Engine is running on a Linux host, or Podman 4.7.0 or later exposes its Docker-compatible API socket.
- The collector runs on the same host as the containers and can read the Docker socket, usually
/var/run/docker.sock. - The collector runs the OpenTelemetry Collector Contrib distribution , or a custom distribution that includes the Docker Stats receiver. The core distribution does not include it.
You'll need an OpenTelemetry Collector deployed on each Docker host. Running the collector as a container next to your other containers is the most common setup and is shown below.
Run the Collector With Access to the Docker Socket
Mount the Docker socket read-only into the collector container. The official collector images run as a non-root user, which cannot open the socket by default. Add the group that owns the socket on the host to the collector container, so the collector can read it without running as root.
Find the group ID of the socket on the Docker host:
stat -c '%g' /var/run/docker.sockThen add the collector to your Docker Compose file, with that group ID in group_add:
services:
otel-collector:
image: otel/opentelemetry-collector-contrib:latest
command: ["--config=/etc/otelcol/config.yaml"]
group_add:
- "999" # group ID of /var/run/docker.sock on the host
volumes:
- ./otelcol-config.yaml:/etc/otelcol/config.yaml:ro
- /var/run/docker.sock:/var/run/docker.sock:roAnyone who can read the Docker socket can control the Docker daemon. Keep the collector configuration under your control, and do not expose the collector's own ports beyond the networks that need them.
Collector Configuration
Add the Docker Stats receiver to your OpenTelemetry Collector configuration and wire it into a metrics pipeline:
receivers:
docker_stats:
endpoint: unix:///var/run/docker.sock
collection_interval: 10s
processors:
resourcedetection:
detectors: [env, system]
service:
pipelines:
metrics:
receivers: [docker_stats]
processors: [resourcedetection]The resourcedetection processor adds host.name to every metric, so you can tell containers on different Docker
hosts apart. The Docker dashboard in this integration uses host.name for its Host filter.
Configuration Options
endpoint: Address of the Docker daemon. Default:unix:///var/run/docker.sock.collection_interval: How often to request container stats. Default:10s.initial_delay: Delay before the first collection. Default:1s.timeout: Timeout for requests to the Docker daemon. Default:5s.api_version: Docker API version to use, as a string such as"1.44". Must be 1.25 or later. By default, the receiver negotiates the version with the daemon.excluded_images: Images whose containers are not monitored. Entries can be exact names, globs such as"*/nginx*", or regular expressions between slashes. Prefix an entry with!to negate it.container_labels_to_metric_labels: Map of container labels to metric attributes.env_vars_to_metric_labels: Map of container environment variables to metric attributes.metrics: Enable or disable individual metrics.
For all available options, see the Docker Stats receiver documentation .
Add Container Labels as Attributes
Docker Compose labels every container with its project and service name. Copy these labels to the metrics, so you can group and filter containers by Compose project and service in Dash0:
receivers:
docker_stats:
container_labels_to_metric_labels:
com.docker.compose.project: docker.compose.project
com.docker.compose.service: docker.compose.serviceEnable Optional Metrics
Enable optional metrics in the metrics section of the receiver:
receivers:
docker_stats:
metrics:
container.uptime:
enabled: true
container.restarts:
enabled: true
container.pids.count:
enabled: true
container.network.io.usage.rx_packets:
enabled: true
container.network.io.usage.tx_packets:
enabled: trueSome memory and block I/O metrics are read from cgroup v1 statistics, such as container.memory.rss,
container.memory.hierarchical_memory_limit, and container.blockio.io_serviced_recursive. Most current Linux
distributions, Docker Desktop, and the Podman machine use cgroup v2, where the receiver does not report these metrics even when you
enable them. Check docker info --format '{{.CgroupVersion}}' to see which version your host uses.
Use Podman
Podman serves a Docker-compatible API on its own socket. Find its address with
podman info --format '{{.Host.RemoteSocket.Path}}', which prints a URI such as unix:///run/podman/podman.sock. Use
the URI as the receiver's endpoint, or mount the socket file (the path after unix://) into the collector container
at /var/run/docker.sock.
On hosts with SELinux enabled, including the Podman machine on macOS, SELinux blocks containers from opening the socket. Disable SELinux labeling for the collector container only:
services:
otel-collector:
security_opt:
- label=disableVerification
- Check the collector logs for errors from the
docker_statsreceiver. - Navigate to the Metrics Explorer in Dash0.
- Search for metrics with the prefix
container.*. - Confirm that
container.cpu.usage.totalandcontainer.memory.usage.totalare reported with acontainer.nameattribute for each running container.
