[Ubuntu] Use Zabbix templates to easily monitor Docker containers

Prerequisites for this article: Zabbix server has been installed and running normally, and the Docker container environment is running on Ubuntu 22.04.

目录:
1. 导入Docker模板
2. 安装并配置Zabbix Agent2
3. Zabbix Agent2 的特定插件配置
4. 在Zabbix中添加主机

1. Import Docker template

To use this template [Docker by Zabbix agent 2] with Zabbix, you need to make sure it is already available in Zabbix. This template is available in Zabbix versions 5.0, 5.4 and 6.0. If you cannot find this template in Configuration->Templates, it may be that it was not imported into your environment after upgrading your Zabbix version. Please note that Zabbix does not automatically modify or import any templates during the upgrade process, so this template must be imported manually. You can download this template file from the official Zabbix Git ( or click here directly ) and import it into your Zabbix instance using the import button in the Configuration->Template page.
Insert image description here

2. Install and configure Zabbix Agent2

Now, we will install Zabbix Agent from the official Zabbix repository. First, add the Zabbix repository to your system:

wget https://repo.zabbix.com/zabbix/6.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.2-4%2Bubuntu22.04_all.deb
sudo dpkg -i zabbix-release_6.2-4+ubuntu22.04_all.deb
sudo apt update

The following are the results of my test installation, already in SUDO SU mode:

root@Virtual-Machine:/home/KnightTest# wget https://repo.zabbix.com/zabbix/6.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.2-4%2Bubuntu22.04_all.deb
--2023-05-22 09:44:00--  https://repo.zabbix.com/zabbix/6.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.2-4%2Bubuntu22.04_all.deb
Resolving repo.zabbix.com (repo.zabbix.com)... 178.128.6.101, 2604:a880:2:d0::2062:d001
Connecting to repo.zabbix.com (repo.zabbix.com)|178.128.6.101|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3780 (3.7K) [application/octet-stream]
Saving to: ‘zabbix-release_6.2-4+ubuntu22.04_all.deb’

zabbix-release_6.2-4+ubuntu22.04_all.deb                             100%[====================================================================================================================================================================>]   3.69K  --.-KB/s    in 0s

2023-05-22 09:44:00 (1.85 GB/s) - ‘zabbix-release_6.2-4+ubuntu22.04_all.deb’ saved [3780/3780]

root@Virtual-Machine:/home/KnightTest# dpkg -i zabbix-release_6.2-4+ubuntu22.04_all.deb
(Reading database ... 209178 files and directories currently installed.)
Preparing to unpack zabbix-release_6.2-4+ubuntu22.04_all.deb ...
Unpacking zabbix-release (1:6.2-4+ubuntu22.04) over (1:6.2-4+ubuntu20.04) ...
Setting up zabbix-release (1:6.2-4+ubuntu22.04) ...
Installing new version of config file /etc/apt/sources.list.d/zabbix-agent2-plugins.list ...
Installing new version of config file /etc/apt/sources.list.d/zabbix.list ...
root@Virtual-Machine:/home/KnightTest# apt update
Hit:1 https://dl.google.com/linux/chrome/deb stable InRelease
Hit:2 http://download.zerotier.com/debian/jammy jammy InRelease
Hit:3 http://cn.archive.ubuntu.com/ubuntu jammy InRelease
Get:4 https://repo.zabbix.com/zabbix-agent2-plugins/1/ubuntu jammy InRelease [4,952 B]
Hit:5 http://cn.archive.ubuntu.com/ubuntu jammy-updates InRelease
Get:6 https://repo.zabbix.com/zabbix/6.2/ubuntu jammy InRelease [4,958 B]
Hit:7 http://cn.archive.ubuntu.com/ubuntu jammy-backports InRelease
Get:8 https://repo.zabbix.com/zabbix-agent2-plugins/1/ubuntu jammy/main Sources [1,002 B]
Get:9 https://repo.zabbix.com/zabbix-agent2-plugins/1/ubuntu jammy/main amd64 Packages [624 B]
Get:10 https://repo.zabbix.com/zabbix/6.2/ubuntu jammy/main Sources [1,952 B]
Get:11 https://repo.zabbix.com/zabbix/6.2/ubuntu jammy/main amd64 Packages [5,491 B]
Get:12 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
Fetched 129 kB in 4s (35.2 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
13 packages can be upgraded. Run 'apt list --upgradable' to see them.
N: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://repo.zabbix.com/zabbix/6.2/ubuntu jammy InRelease' doesn't support architecture 'i386'
root@Virtual-Machine:/home/KnightTest#

Install and configure Zabbix Agent2

sudo apt install zabbix-agent2

The following are the results of my test installation, already in SUDO SU mode:

root@Virtual-Machine:/home/KnightTest# apt install zabbix-agent2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libllvm13 zabbix-agent2-plugin-mongodb zabbix-agent2-plugin-postgresql
Use 'sudo apt autoremove' to remove them.
The following packages will be upgraded:
  zabbix-agent2
1 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
Need to get 4,155 kB of archives.
After this operation, 205 kB disk space will be freed.
Get:1 https://repo.zabbix.com/zabbix/6.2/ubuntu jammy/main amd64 zabbix-agent2 amd64 1:6.2.9-1+ubuntu22.04 [4,155 kB]
Fetched 4,155 kB in 2s (1,945 kB/s)
(Reading database ... 209178 files and directories currently installed.)
Preparing to unpack .../zabbix-agent2_1%3a6.2.9-1+ubuntu22.04_amd64.deb ...
Unpacking zabbix-agent2 (1:6.2.9-1+ubuntu22.04) over (1:6.0.17-1+ubuntu22.04) ...
Setting up zabbix-agent2 (1:6.2.9-1+ubuntu22.04) ...
Installing new version of config file /etc/zabbix/zabbix_agent2.conf ...
Processing triggers for man-db (2.10.2-1) ...
root@Virtual-Machine:/home/KnightTest#

Change the corresponding zabbix server parameters in the /etc/zabbix/zabbix_agent2.conf file. Mainly as follows:

Server=<Zabbix_Server_IP>
ServerActive=<Zabbix_Server_IP>
Hostname=<Hostname_Of_Ubuntu_Client>

3. Specific plug-in configuration for Zabbix Agent2

Zabbix agent2 provides some specific plug-in configuration parameters. Normally, these specific plug-in related parameters are optional. You can find a complete list of plugin configuration parameters in the Zabbix documentation. In the new version of Zabbix agent2, plugin-specific parameters are defined in a separate plugin configuration file, located in the /etc/zabbix/zabbix_agent2.d/plugins.d/ directory. However, in older versions, these parameters were defined directly in the zabbix_agent2.conf file.

For the Zabbix agent2 Docker plugin (used for monitoring Docker), we must configure the unix-socket file location of the Docker service in docker.conf. This can be achieved via the following plugin parameters:

root@Virtual-Machine:/home/KnightTest# cat /etc/zabbix/zabbix_agent2.d/plugins.d/docker.conf
### Option: Plugins.Docker.Endpoint
#       Docker API endpoint.
#
# Mandatory: no
# Default: unix:///var/run/docker.sock
Plugins.Docker.Endpoint=unix:///var/run/docker.sock

In the above case, the default location of the unix-socket file serving Docker is set according to your own modifications.

Add the zabbix user to the Docker group by executing the following command:

usermod -aG docker zabbix

After all configurations are completed, restart the zabbix-agent2 service and check the status:

sudo systemctl restart zabbix-agent 
sudo systemctl enable zabbix-agent 
sudo systemctl status zabbix-agent 
root@Virtual-Machine:/home/KnightTest# systemctl status zabbix-agent2
● zabbix-agent2.service - Zabbix Agent 2
     Loaded: loaded (/lib/systemd/system/zabbix-agent2.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-05-22 10:41:48 CST; 3s ago
   Main PID: 3049063 (zabbix_agent2)
      Tasks: 8 (limit: 4614)
     Memory: 6.8M
        CPU: 89ms
     CGroup: /system.slice/zabbix-agent2.service
             └─3049063 /usr/sbin/zabbix_agent2 -c /etc/zabbix/zabbix_agent2.conf

522 10:41:48 knight-Virtual-Machine systemd[1]: Started Zabbix Agent 2.
522 10:41:48 knight-Virtual-Machine zabbix_agent2[3049063]: Starting Zabbix Agent 2 (6.2.9)
522 10:41:48 knight-Virtual-Machine zabbix_agent2[3049063]: Zabbix Agent2 hostname: [KnightTestEnv]
522 10:41:48 knight-Virtual-Machine zabbix_agent2[3049063]: Press Ctrl+C to exit.

4. Add host in Zabbix

Now you need to create a host for your Docker instance. Set the hostname and assign the host group - I will assign it to the Linux servers host group. Associate the Docker by Zabbix agent 2 template and Linux by Zabbix Agent to the host. Because the Zabbix agent2 template is used to collect data, a proxy interface needs to be added to this host. The address of the interface is the address of the machine running the Docker container. Click the Add button to complete the host configuration.
Insert image description here
You can view the information about Docker in Zabbix later. Only partial screenshots are below.
Insert image description here
Insert image description here

Replenish:

How to solveN: Skipping acquire of configured file 'main/binary-i386/Packages' as repository 'https://repo.zabbix.com/zabbix/6.2/ubuntu jammy InRelease' doesn't support architecture 'i386'

Modify **/etc/apt/sources.list.d/zabbix.list ** to add the "[arch=amd64]" option before the URL of the software library to limit it to the amd64 architecture:

deb [arch=amd64] https://repo.zabbix.com/zabbix/6.2/ubuntu jammy main

Save and close the file, then run the "sudo apt update" command to refresh the package list. This will skip the i386 package for the zabbix repository and prevent the error message from appearing.

If you need to install a package in the zabbix software library that is only applicable to the i386 architecture, you can try to manually download the .deb package file on the warehouse website and use "dpkg" to install it. However, be aware that it may cause dependency issues and may not work as expected.

Guess you like

Origin blog.csdn.net/u012153104/article/details/130802759