{
  "id": 6241531,
  "title": "How to Monitor a Docker Container's CPU and Memory Usage",
  "url": "https://urgent.news/2026/09/08/how-to-monitor-a-docker-containers-cpu-and-memory-usage",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-08T05:19:34.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/opservo/how-to-monitor-a-docker-containers-cpu-and-memory-usage-20f4"
  },
  "original_language": "en",
  "account": "Monitoring Docker containers' CPU and memory usage is crucial for maintaining application performance in production environments. Docker provides built-in tools to track this data, eliminating the need for dedicated SREs. The `docker stats` command offers live updates, displaying CPU percentage, memory usage versus limit, network I/O, and block I/O for all running containers. To focus on specific containers, use `docker stats --no-stream` to generate a single snapshot, or customize the output with `docker stats --format`.\n\nUnderstanding memory metrics requires attention to detail. The first number represents current RSS-style usage, while the second shows the limit (or total RAM if no limit is set). Without memory limits, a container can consume all available RAM, leading to OOM-kills and service disruptions. Setting hard limits with `--memory` and soft warning thresholds with `--memory-reservation` prevents such issues. Use `docker inspect` and `/sys/fs/cgroup/memory/docker/` to verify limits on already-running containers.\n\nFor historical data collection, `docker stats` alone is insufficient. A simple shell loop can log snapshots every 30 seconds to a CSV file, providing a basic audit trail. However, this approach lacks the robustness of dedicated monitoring solutions. cAdvisor, an open-source exporter from Google, scrapes cgroup data and exposes metrics in a Prometheus-compatible format. Deploying cAdvisor as a container allows access to CPU and memory graphs via its web UI or Prometheus. Key metrics to monitor include `container_cpu_usage_seconds_total`, `container_memory_usage_bytes`, and `container_memory_working_set_bytes`.\n\nEstablishing alert thresholds is essential for timely issue resolution. Focus on sustained CPU usage above 80% for over five minutes, memory usage exceeding 90% of the container limit, and steadily increasing memory usage with no plateau. Monitoring container restart counts can also reveal silent crashes. While collecting data is essential, defining clear alerting thresholds ensures prompt intervention before problems escalate. For teams without dedicated ops personnel, automated tools like Opservo simplify anomaly detection and alerting, bridging the gap between data collection and actionable insights. Start with `docker stats`, enforce resource limits, and gradually integrate more advanced monitoring solutions as needed.",
  "summary": "Learn how to track Docker container CPU and memory usage with built-in tools and practical commands — no dedicated SRE required. Your app slows to a crawl at 2 a.m., and you have no idea which container is eating all the CPU. By morning the problem has vanished, but you're left with zero evidence and a vague sense of dread. If you're running Docker in production without dedicated monitoring, that…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}