Docker container metrics – Containerization with Docker

Metrics to monitor

Monitoring metrics is a complex subject, and it would depend mostly on your use case. However, the following are some guidelines on what metrics you want to monitor.

Host metrics

You need to monitor your host metrics as your containers run on them. Some of the metrics that you can watch are as follows:

  • Host CPU: It’s good to know whether your host has sufficient CPU to run your containers. If not, it might terminate some of your containers to account for that. So, to ensure reliability, you need to keep this in check.
  • Host memory: Like the host CPU, you need to watch the host memory to detect issues such as memory leaks and runaway memory.
  • Host disk space: As Docker containers use the host filesystem to store transient and persistent files, you need to monitor it.

Docker container metrics

Docker container metrics are the next thing to consider:

  • Container CPU: This metric will provide the amount of CPU used by the Docker container. You should monitor it to understand the usability pattern and decide where to place your container effectively.
  • Throttled CPU time: This metric allows us to understand the total time when the CPU was throttled for a container. This lets us know whether a particular container needs more CPU time than others, and you can adjust the CPU share constraint accordingly.
  • Container memory fail counters: This metric provides the number of times the container requested more than the allocated memory. It will help you understand what containers require more than the allocated memory, and you can plan to run those containers accordingly.
  • Container memory usage: This metric will provide the amount of memory used by the Docker container. You can set memory limits according to the usage.
  • Container swap: This metric will tell you what containers were using swap instead of RAM. It helps us identify memory-hungry containers.
  • Container disk I/O: This is an important metric and will help us understand containers’ disk profiles. Spikes can indicate a disk bottleneck or suggest that you might want to revisit your storage driver configuration.
  • Container network metrics: This metric will tell us how much network bandwidth the containers use and help us understand traffic patterns. You can use these to detect an unexpected network spike or a denial-of-service attack.

Important tip

Profiling your application during the performance testing phase in the non-production environment will give you a rough idea of how the system will behave in production. The actual fine-tuning of your application begins when you deploy them to production. Therefore, monitoring is critical, and fine-tuning is a continuous process.

So far, we have been running commands to do most of our work. That is the imperative way of doing

this. But what if I told you that instead of typing commands, you could declare what you want, and something could run all the required commands on your behalf? That is known as the declarative method of managing an application. Docker Compose is one of the popular tools to achieve this. We’ll have a look at this in the next section.

Leave a Reply

Your email address will not be published. Required fields are marked *