Prometheus exporter for Docker containers resource usage statistics. It converts the output from Docker API /containers/(id)/stats
endpoint into a Prometheus-compatible format. The exporter automatically detects all Docker containers and provides the metrics for them.
git clone git@github.com:GrzegorzMika/docker_stats_exporter.git
cd docker_stats_exporter
go build .
./docker_stats_exporter --version
For pre-built binaries please take a look at the releases.
docker run \
-v /var/run/docker.sock:/var/run/docker.sock \
-p 9273:9273 \
ghcr.io/grzegorzmika/docker_stats_exporter:latest
Exporter Docker image is also available via Docker Hub gregmika/docker_stats_exporter
.
curl http://localhost:9273/metrics
Add a block to the scrape_configs
of your prometheus.yml
config file:
scrape_configs:
- job_name: docker_stats_exporter
static_configs:
- targets: ['<<DOCKER-STATS-EXPORTER-HOSTNAME>>:9273']
and adjust the host name accordingly.
Name | Description | Default value |
---|---|---|
web.listen-address | Address to listen on for web interface and telemetry. | :9273 |
web.telemetry-path | Path under which to expose metrics. | /metrics |
web.timeout | Docker Stats Exporter API request timeout. | 5s |
internal.max-concurrent-requests | Maximum number of concurrent Docker API requests. | 10 |
version | Show version information and exit. |
docker_stats_up
- Whether scraping Docker Stats metrics was successful.docker_container_read_statistics_time_seconds
- Last time read operation took place on a containerdocker_container_cpu_usage_seconds_total
- Total CPU usage for a container in secondsdocker_container_cpu_system_usage_seconds_total
- Total system CPU usage in secondsdocker_container_cpu_usage_delta_seconds
- Delta CPU usage for a container in secondsdocker_container_cpu_system_usage_delta_seconds
- Delta system CPU usage in secondsdocker_container_cpu_number
- Number of CPUs for a containerdocker_container_memory_usage_bytes_total
- Memory usage for a container in bytes including cachedocker_container_memory_cached_usage_bytes_total
- Memory usage for a container as cachedocker_container_memory_limit_bytes_total
- Memory limit for a container in bytesdocker_container_network_bytes_received_bytes_total
- Network bytes received for a containerdocker_container_network_bytes_sent_bytes_total
- Network bytes sent for a containerdocker_container_network_packets_received_total
- Network packets received for a containerdocker_container_network_packets_sent_total
- Network packets sent for a containerdocker_container_network_errors_received_total
- Network errors received for a containerdocker_container_network_errors_sent_total
- Network errors sent for a container
The measurements are labeled with container id, container name, image id, image name and host name.
To calculate the values shown by the docker stats
command of the docker cli tool the following formulas can be used:
- CPU usage %
(docker_container_cpu_usage_delta_seconds / docker_container_cpu_system_usage_delta_seconds) * docker_container_cpu_number * 100.0
- Memory usage %
(docker_container_memory_usage_bytes_total - docker_container_memory_cached_usage_bytes_total) / docker_container_memory_limit_bytes_total * 100.0