In a Docker infrastructure, monitoring the containers is vital to ensure that a single container do not end up abusing the host machine and crash other containers.
Docker container monitoring involves keeping an eye on the metrics such as available CPU, mem, blkio, etc. These metrics for a container can be seen with the command ‘docker stats‘.
But monitoring containers from the backend manually is a time-consuming process and not feasible for pro-active management of machines.
Save your Docker containers from crash
This makes it important to have a monitoring system setup for the Docker containers.
Docker container monitoring with Zabbix
We setup a custom Zabbix server for our internal system monitoring purposes. Zabbix is an open source monitoring software for network and applications.
Zabbix consists of a server running in a container and agents running on the machines that need to be monitored. The machine data are stored in a database.
To install Zabbix server in a Docker container, create a container using the ‘docker-zabbix’ image:
docker run -d -P --name zabbix berngp/docker-zabbix
To monitor Docker containers using Zabbix, a Zabbix agent has to be installed in the Docker machine. Zabbix agent is an application that tracks the metrics of systems being monitored.
We added our Docker infrastructure to that monitoring system with these steps:
1. Create Zabbix Agent container
The first step is to create a container with Zabbix agent image, specifying the Zabbix server IP, with this command:
docker run \ --name=zabbix-agent-xxl \ -h $(hostname) \ -p 10050:10050 \ -v /:/rootfs \ -v /var/run:/var/run \ -e "ZA_Server=<ZABBIX SERVER IP/DNS NAME>" \ -d monitoringartist/zabbix-agent-xxl-limited:latest
You can see the newly created Zabbix Agent container running in the Docker machine, with the ‘docker ps’ command:
2. Configure the Zabbix Agent
The configuration file for the Zabbix Agent is available at ‘/etc/zabbix/zabbix_agentd.conf’. This file contains details such as Zabbix server and other parameters.
In the Zabbix server, add the hosts (containers to be monitored) and the triggers for them. This can be done easily with the help of Zabbix templates.
The container metrics for CPU, I/O, memory, disk usage, etc. can be retrieved from their containers’ cgroup stats folders and monitored using Zabbix.
To test the Zabbix agent, the utility ‘zabbix_agent_bench’, the bench-marking tool, can be used.
[ Running a Docker infrastructure doesn’t have to be hard, or costly. Get world class Docker management services at affordable pricing. ]
3. Checking the Zabbix Agent logs
Once the Zabbix Agent starts running in the machine, you can check the logs related to it using ‘docker logs’ command. This is usually relevant for trouble-shooting purposes.
4. Monitoring the Docker containers
Once the Zabbix service starts working fine, you can view reports on the Docker container performance with Zabbix graphs. CPU, memory, disk space, I/O, etc. are monitored.
By monitoring the Docker containers, it is possible to identify the containers that are taking up more resources and to limit the usage based on their plans.
Read our post on ‘How to improve Docker performance with resource control using cgroups‘, to know more about what to do next, based on monitoring results.
[ Are your spending too much time managing your Docker containers? Our Docker experts take care of your infrastructure and ensure its smooth functioning. ]
To summarize..
Today we saw how to implement Docker container monitoring with the help of Zabbix. Being open source, it is possible to customize the Zabbix based on business requirements.
After setting up the monitoring system, more vital part is 24/7 proactive monitoring of the containers to avoid a crash or resource shortage.
At Bobcares, our 24/7 expert engineers monitor and maintain the Docker container resources in an optimal way to ensure the best performance.
If you’d like to know how to manage your Docker system and to get the best out of them for your business, we’d be happy to talk to you.
Thank you for your artcile.
“Zabbix consists of a server running in a container” – is it a necessary requirement for Zabbix server to be installed inside a container?
Actually, our Zabbix server is installed just as an ordinary VM. We would like to monitor our Docker containers without any modifications regarding to Zabbix server itself.
Thank you!
Hi Alexey,
If you need assistance, please click here to talk to our server admins.
could you finally did that? I have the same issue.