Monitoring Docker Containers with cAdvisor is a common requirement for VPS administrators. This guide provides practical instructions that you can follow on Ubuntu 22.04/24.04 or Debian 12, though most steps apply to other distributions as well.
Prerequisites
- Docker installed (for containerized monitoring)
- Open ports: 3000 (Grafana), 9090 (Prometheus)
- Basic familiarity with the Linux command line
Stack Installation
For production deployments, consider implementing high availability by running multiple instances behind a load balancer. This approach provides both redundancy and improved performance under heavy load.
# docker-compose.yml for monitoring stack
version: '3.8'
services:
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
ports:
- "9090:9090"
restart: unless-stopped
grafana:
image: grafana/grafana:latest
volumes:
- grafana_data:/var/lib/grafana
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=changeme
restart: unless-stopped
volumes:
prometheus_data:
grafana_data:
Make sure to restart the service after applying these changes. Some settings require a full restart rather than a reload to take effect.
Advanced Settings
Performance benchmarks show that properly tuned cadvisor can handle significantly more concurrent connections than the default configuration. The key improvements come from adjusting worker processes and connection pooling.
Dashboard Configuration
The docker component plays a crucial role in the overall architecture. Understanding how it interacts with cadvisor will help you make better configuration decisions.
# prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
- job_name: 'cadvisor'
static_configs:
- targets: ['localhost:9090']
Make sure to restart the service after applying these changes. Some settings require a full restart rather than a reload to take effect.
Alert Rule Setup
After applying these changes, monitor the server's resource usage for at least 24 hours to ensure stability. Tools like htop, iostat, and vmstat can provide real-time insights into system performance.
# docker-compose.yml for monitoring stack
version: '3.8'
services:
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus_data:/prometheus
ports:
- "9090:9090"
restart: unless-stopped
grafana:
image: grafana/grafana:latest
volumes:
- grafana_data:/var/lib/grafana
ports:
- "3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=changeme
restart: unless-stopped
volumes:
prometheus_data:
grafana_data:
Note that file paths may vary depending on your Linux distribution. The examples here are for Debian/Ubuntu; adjust paths accordingly for RHEL/CentOS-based systems.
- Maintain runbooks for common operations
- Use version control for configuration files
- Test disaster recovery procedures regularly
Conclusion
This guide covered the essential steps for working with cadvisor on a VPS environment. For more advanced configurations, refer to the official documentation. Don't hesitate to reach out to our support team if you need help with your specific setup.