By the end of the last post we finished with a running Zabbix server which uses PostgreSQL as it’s back-end database. In addition a Zabbix agent is running on the same host, so the monitoring host itself is present in the Zabbix console. In this post will deploy the Zabbix agent on three PostgreSQL Patroni nodes and later on configure Zabbix to monitor the PostgreSQL instances.
As the agent deployment works exactly the same, no matter the host, I’ll show it on one PostgreSQL/Patroni host only. Just repeat that on the other nodes and you should be fine. The deployment of the agent from source code, is not much different than deploying the Zabbix. First of all get the source code:
postgres@patroni1:/home/postgres/ [pg141] wget https://cdn.zabbix.com/zabbix/sources/stable/5.4/zabbix-5.4.7.tar.gz postgres@patroni1:/home/postgres/ [pg141] tar axf zabbix-5.4.7.tar.gz postgres@patroni1:/home/postgres/ [pg141] cd zabbix-5.4.7/
The recent version of the Zabbix agent (v2) is written in Go so this needs to be installed (and the other dependencies), before installing the agent. As Debian 11 comes with Go 1.15 which is too old for the agent, we need to fetch Go directly:
postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] sudo apt install -y libpcre3-dev postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] wget https://go.dev/dl/go1.17.3.linux-amd64.tar.gz postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] tar axf go1.17.3.linux-amd64.tar.gz postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] sudo mv go /usr/local/ postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] export PATH=$PATH:/usr/local/go/bin/ postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] go version go version go1.17.3 linux/amd64 postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] ./configure --prefix=/u01/app/postgres/product/zabbix_5.4.7 --enable-agent2 checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /usr/bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes ... config.status: creating man/Makefile config.status: creating include/config.h config.status: executing depfiles commands Configuration: Detected OS: linux-gnu Install path: /u01/app/postgres/product/zabbix_5.4.7 Compilation arch: linux Compiler: cc Compiler flags: -g -O2 Library-specific flags: Enable server: no Enable proxy: no Enable agent: no Enable agent 2: yes Enable web service: no Enable Java gateway: no LDAP support: no IPv6 support: no *********************************************************** * Now run 'make install' * * * * Thank you for using Zabbix! * * * ***********************************************************
Ready to install:
postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] make install Making install in src make[1]: Entering directory '/home/postgres/zabbix-5.4.7/src' Making install in libs make[2]: Entering directory '/home/postgres/zabbix-5.4.7/src/libs' Making install in zbxcrypto ... go: downloading github.com/go-sql-driver/mysql v1.5.0 go: downloading gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 go: downloading github.com/go-ldap/ldap v3.0.3+incompatible go: downloading github.com/godbus/dbus v4.1.0+incompatible ... make[2]: Nothing to be done for 'install-exec-am'. make[2]: Nothing to be done for 'install-data-am'. make[2]: Leaving directory '/home/postgres/zabbix-5.4.7' make[1]: Leaving directory '/home/postgres/zabbix-5.4.7' postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] /u01/app/postgres/product/zabbix_5.4.7/sbin/zabbix_agent2 --version zabbix_agent2 (Zabbix) 5.4.7 Revision 84dc2ec5dc 28 October 2021, compilation time: Nov 30 2021 13:37:39 Copyright (C) 2021 Zabbix SIA License GPLv2+: GNU GPL version 2 or later . This is free software: you are free to change and redistribute it according to the license. There is NO WARRANTY, to the extent permitted by law. We use the library Eclipse Paho (eclipse/paho.mqtt.golang), which is distributed under the terms of the Eclipse Distribution License 1.0 (The 3-Clause BSD License) available at https://www.eclipse.org/org/documents/edl-v10.php We use the library go-modbus (goburrow/modbus), which is distributed under the terms of the 3-Clause BSD License available at https://github.com/goburrow/modbus/blob/master/LICENSE
That’s it. Adjust the configuration and create a systemd service definition:
postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] ln -s /u01/app/postgres/product/zabbix_5.4.7/ /u01/app/postgres/product/zabbix-current postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] egrep -v "^$|^#" /u01/app/postgres/product/zabbix-current/etc/zabbix_agent2.conf PidFile=/u01/app/postgres/local/dmk/tmp/zabbix_agent2.pid LogFile=/u01/app/postgres/local/dmk/log/zabbix_agent2.log Server=192.168.100.173 ServerActive=192.168.100.173 Hostname=patroni1.it.dbi-services.com ControlSocket=/tmp/agent.sock postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] cat /etc/systemd/system/zabbix-agent.service [Unit] Description=dbi services zabbix agent service After=network.target,postgres-zabbix.service [Service] User=postgres Type=notify ExecStart=/u01/app/postgres/product/zabbix-current/sbin/zabbix_agent2 Restart=always RestartSec=10s LimitNOFILE=40000 [Install] WantedBy=multi-user.target postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] sudo systemctl enable zabbix-agent.service postgres@patroni1:/home/postgres/zabbix-5.4.7/ [pg141] sudo reboot postgres@patroni1:/home/postgres/ [pg141] systemctl status zabbix-agent.service ● zabbix-agent.service - dbi services zabbix agent service Loaded: loaded (/etc/systemd/system/zabbix-agent.service; enabled; vendor preset: enabled) Active: activating (start) since Tue 2021-11-30 14:17:55 CET; 1min 28s ago Main PID: 912 (zabbix_agent2) Tasks: 5 (limit: 1133) Memory: 12.8M CPU: 39ms CGroup: /system.slice/zabbix-agent.service └─912 /u01/app/postgres/product/zabbix-current/sbin/zabbix_agent2 Nov 30 14:17:55 patroni1 zabbix_agent2[912]: Starting Zabbix Agent 2 (5.4.7) Nov 30 14:17:55 patroni1 zabbix_agent2[912]: Zabbix Agent2 hostname: [patroni1.it.dbi-services.com] Nov 30 14:17:55 patroni1 zabbix_agent2[912]: Press Ctrl+C to exit.
Once this is done and the agent is running you can add the host to the Zabbix configuration:
Repeat all that for the remaining nodes and then you have a setup like this:
Adding PostgreSQL metrics is just a matter of attaching the template to the hosts and a few moments later the metrics are there:
Easy and simple to setup.
Cet article Open source monitoring solutions (2) – Zabbix agents and PostgreSQL monitoring est apparu en premier sur Blog dbi services.