Monitor Docker using Zabbix

Pre-requisite:

  • The difference between Zabbix Agent and Zabbix Agent 2 can be read here.
  • Uninstall Zabbix Agent if already installed.

$ sudo apt-get remove zabbix-agent
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages will be REMOVED:
zabbix-agent
0 upgraded, 0 newly installed, 1 to remove and 146 not upgraded.
After this operation, 664 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database … 153093 files and directories currently installed.)
Removing zabbix-agent (1:3.0.12+dfsg-1) …
Processing triggers for man-db (2.8.3-2ubuntu0.1) …

Step 1: Log into Docker host

Step 2: Add repository for installing Zabbix components

$ sudo wget https://repo.zabbix.com/zabbix/6.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.2-1+ubuntu18.04_all.deb
$ sudo dpkg -i zabbix-release_6.2-1+ubuntu18.04_all.deb
$ sudo apt update

Step 3: Now, install Zabbix agent 2 with the following command

$ apt install zabbix-agent2

Step 4: Edit Zabbix configuration to point to Zabbix server IP address

$ sudo vi /etc/zabbix/zabbix_agent2.conf

Find the line that says Server and add your Zabbix server IP address
Server = 10.10.10.10

All in One WordPress Hosting Starts at 30$ per month
All in One WordPress Hosting
WordPress
High optimized WordPress hosting, secure firewall, HTTPS, Backup, hack-fix guarantee and many others at 30$ per month

Find the line that says ServerActive and add your Zabbix server IP address
ServerActive = 10.10.10.10

Find the line that says Hostname and specify the host name of Docker host. Hostname is case sensitive, must match exactly what configured in Zabbix server
Hostname=DOCKERHOSTNAME

Step 5: Restart Zabbix Agent 2

$ sudo systemctl restart zabbix-agent2.service

Step 6: Add zabbix user to the Docker group

Typically, name of Docker group is ‘docker’, so you can straightaway execute following command to add ‘zabbix’ user to ‘docker’ group

$ sudo gpasswd -a zabbix docker

[Optional] Incase you prefer to have a check to identify the exact Docker group name, navigate to /var/run and look at the owner of the docker.sock file

$ cd /var/run
$ ls -lstrh | grep docker

[Optional] To verify if the ‘zabbix’ user is successfully added to ‘docker’ group,

$ sudo apt install members
$ members docker

Step 7: Review Zabbix Agent 2 logs to ensure the agent is not experiencing any problem in communicating with Zabbix server

$ tail -f /var/log/zabbix/zabbix_agent2.log

Important: Do not forget to attach ‘Docker by Zabbix agent 2’ template to the Docker host in Zabbix Server