When running containerized workloads on a VPS, monitoring resource utilization across containers becomes critical. Unlike traditional server monitoring, container monitoring must account for ephemeral instances, shared kernel resources, and dynamic scaling. This guide walks through three complementary monitoring approaches — from the lightweight docker stats CLI to a full Prometheus and cAdvisor stack. If you are evaluating VPS plans to run containers, start with our VPS comparison table to find a provider with sufficient CPU and RAM for your workloads.
What Youll Need
- A VPS running Ubuntu 22.04 or Debian 12 (minimum 2 GB RAM, 2 vCPUs)
- Docker Engine installed and configured
- SSH access with sudo privileges
- Ports 8080 (cAdvisor) and 9090 (Prometheus) available in your firewall
- Basic familiarity with the Linux command line and YAML configuration
Step 1: Quick Monitoring with Docker Stats
The quickest way to see container resource usage is the built-in docker stats command. It shows live CPU, memory, network I/O, and block I/O for all running containers in a table format.
docker stats --all --no-streamRemove --no-stream to get a live-updating view. While useful for ad-hoc debugging, docker stats does not persist data. For historical retention and alerting, you need a dedicated monitoring stack.
Step 2: Deploy cAdvisor for Container Metrics
cAdvisor (Container Advisor) is an open-source agent from Google that collects, aggregates, and exports resource usage and performance data for running containers. It exposes a web UI on port 8080 and emits Prometheus-compatible metrics.
Deploy cAdvisor as a Docker container:
docker run -d \
--name=cadvisor \
--restart=unless-stopped \
-p 8080:8080 \
-v /:/rootfs:ro \
-v /var/run:/var/run:ro \
-v /sys:/sys:ro \
-v /var/lib/docker/:/var/lib/docker:ro \
-v /dev/disk/:/dev/disk:ro \
--privileged \
--device=/dev/kmsg \
gcr.io/cadvisor/cadvisor:latestVerify it is running by visiting http://<your-vps-ip>:8080. The dashboard shows per-container CPU, memory, network, and filesystem metrics in real time.
Step 3: Set Up Prometheus for Time-Series Storage
Prometheus is a time-series database and monitoring system that scrapes cAdvisor metrics endpoint and stores them for querying and alerting.
Create a Prometheus configuration file prometheus.yml:
global:\n scrape_interval: 15s\n evaluation_interval: 15s\n\nscrape_configs:\n - job_name: cadvisor\n static_configs:\n - targets: [localhost:8080]Run Prometheus as a container, mounting the config file:
docker run -d \
--name=prometheus \
--restart=unless-stopped \
-p 9090:9090 \
-v $(pwd)/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus:latestAccess the Prometheus UI at http://<your-vps-ip>:9090. You can run PromQL queries like container_cpu_usage_seconds_total or container_memory_usage_bytes to inspect container health over time.
Step 4: Add Grafana for Visual Dashboards (Optional)
For a richer visualization, add Grafana on top of Prometheus:
docker run -d \
--name=grafana \
--restart=unless-stopped \
-p 3000:3000 \
grafana/grafana:latestLog in at http://<your-vps-ip>:3000 (default admin/admin), add Prometheus as a data source (http://localhost:9090), and import the community cAdvisor dashboard (ID 14282) for pre-built visualizations.
Step 5: Set Up Resource Alerts
Create an alerting rule file alerts.yml to send notifications when containers exceed thresholds:
groups:\n - name: container_alerts\n rules:\n - alert: HighContainerCPU\n expr: sum(rate(container_cpu_usage_seconds_total[1m])) by (name) > 0.8\n for: 5m\n labels:\n severity: warning\n annotations:\n summary: Container {{ $labels.name }} CPU above 80% for 5 minutes\n\n - alert: HighContainerMemory\n expr: container_memory_usage_bytes / container_spec_memory_limit_bytes > 0.9\n for: 5m\n labels:\n severity: warning\n annotations:\n summary: Container {{ $labels.name }} memory above 90%Reference alerts.yml in your prometheus.yml under the rule_files directive and restart Prometheus.
Troubleshooting Common Issues
- cAdvisor shows no data — Ensure cAdvisor has access to
/var/lib/dockerand the host filesystem. Re-run with--privilegedflag. - Prometheus cannot reach cAdvisor — Use
host.docker.internal:8080instead oflocalhost:8080when running in Docker bridge network mode, or use--network=host. - Grafana shows No data — Verify Prometheus data source URL is reachable from the Grafana container. Use
http://prometheus:9090if both are on the same Docker network. - High memory usage from monitoring stack — cAdvisor can use 100–300 MB RAM on a busy host. Consider reducing
scrape_intervalto 30s or 60s on low-memory VPS plans.
Conclusion
This stack gives you container-level visibility from quick CLI checks (docker stats) to long-term trending and alerting (cAdvisor + Prometheus + Grafana). The setup runs comfortably on a 2 GB VPS with typical containerized workloads. For VPS recommendations that match your monitoring requirements, check our VPS comparison table for CPU and RAM options.

Leave a Reply
You must be logged in to post a comment.