DEV Community

Cover image for How to Monitor Network Bandwidth of Docker Containers
Syed Sadat Ali
Syed Sadat Ali

Posted on

How to Monitor Network Bandwidth of Docker Containers

To check the network bandwidth of a Docker instance, you can use several methods depending on what specifics you want to monitor (e.g., overall network usage, per-container bandwidth, etc.). Here’s a step-by-step guide for different approaches:

1. Using Docker Stats Command

The docker stats command provides real-time statistics for containers, including network I/O.

docker stats
Enter fullscreen mode Exit fullscreen mode

This command shows information including network input and output for each running container. The NET I/O column shows the amount of data received and sent by each container.

2. Using Docker Network Inspect

If you need detailed information about a specific network:

docker network inspect <network_name>
Enter fullscreen mode Exit fullscreen mode

This will give you details about the network configuration and connected containers but does not directly show bandwidth usage.

3. Using Network Monitoring Tools

For more detailed bandwidth monitoring, you may need external tools:

  • iftop or nload: These tools can be installed on the host machine to monitor network traffic. You’ll need to look at traffic on the Docker network interfaces (e.g., docker0 or br-<network_id>).
  sudo iftop -ni docker0
Enter fullscreen mode Exit fullscreen mode

or

  sudo nload
Enter fullscreen mode Exit fullscreen mode
  • Prometheus & Grafana: For more comprehensive monitoring, you can set up Prometheus with a Docker exporter and visualize the metrics using Grafana. The Docker exporter can provide metrics on network usage.

4. Using cAdvisor

cAdvisor is a container monitoring tool that provides detailed metrics about Docker containers, including network usage.

  • Install cAdvisor:
  docker run -d \
    --name=cadvisor \
    --volume=/:/rootfs:ro \
    --volume=/var/run:/var/run:ro \
    --volume=/sys:/sys:ro \
    --volume=/var/lib/docker/:/var/lib/docker:ro \
    --publish=8080:8080 \
    google/cadvisor:latest
Enter fullscreen mode Exit fullscreen mode
  • Access the cAdvisor Web Interface: Visit http://localhost:8080 to view metrics, including network statistics.

5. Custom Monitoring with Network Tools

You can use network traffic monitoring tools directly within containers to get more granular data:

  • Install iperf or similar tools within your containers and run tests to measure bandwidth.
  docker exec -it <container_id> iperf -s
Enter fullscreen mode Exit fullscreen mode
  docker exec -it <container_id> iperf -c <server_ip>
Enter fullscreen mode Exit fullscreen mode

Reference : https://docs.docker.com/reference/cli/docker/network/

Top comments (0)