If you're running Docker containers on a server, monitoring their performance using command-line tools can be time-consuming and difficult to visualize. In this guide, I’ll show you how to monitor your Docker services using Grafana, Prometheus, and cAdvisor—all through a web interface, without relying on CLI tools after setup.
You’ll be able to:
- Track real-time Docker container metrics
- Visualize system performance through a Grafana dashboard
- Use Prometheus to scrape and expose container metrics
- Deploy everything using simple Docker commands
Step 1: Run Your Docker Containers
Make sure your Docker containers are already running. Here’s a snapshot of my currently active containers:
Step 2: Install cAdvisor in a Docker Container
To collect container metrics in real time, we’ll run cAdvisor inside a dedicated Docker container.
Run the cAdvisor Container:
sudo docker run
--volume=/:/rootfs:ro
--volume=/var/run:/var/run:rw
--volume=/sys:/sys:ro
--volume=/var/lib/docker/:/var/lib/docker:ro
--publish=8080:8080
--detach=true
--name=cadvisor
--privileged
--device=/dev/kmsg
gcr.io/cadvisor/cadvisor:v0.49.1
Step 3: Set Up Prometheus for Metrics Collection
scrape_configs: - job_name: 'cadvisor' static_configs: - targets: ['localhost:8080']
docker run -d --name=prometheus -p 9090:9090 -v /home/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
docker run -d -p 3000:3000 --name=grafana --restart always -v grafana-storage:/var/lib/grafana grafana/grafana
- Go to http://localhost:3000
- Login → Click the ⚙️ (Settings/Gear icon) → Data Sources
- Click Add data source
- Choose Prometheus
- Set URL to: http://host.docker.internal:9090 (Windows/macOS)
- or http://x.x.x.x:9090 (for external access)
- Click Save & Test
Step 6: Import Docker Monitoring Dashboard
- In Grafana, click ➕ → Import
- Enter Dashboard ID: 14282
- Click Load
- Choose your Prometheus data source
- Click Import
- Save the dashboard with your preferred name
- Visit: 1. https://grafana.com/grafana/dashboards/14282
- Click “View JSON”
- Right-click → Save As → Save it as docker-dashboard.json
- Go back to Grafana → ➕ Import → Upload JSON file
- Select Prometheus as the data source → Click Import
Final Result: Real-Time Docker Monitoring Dashboard
- CPU & memory usage per container
- Disk I/O, network throughput
- Container uptime & health
- System-wide Docker stats
Comments
Post a Comment