3. Go to the directory with the PostgreSQL template.
cd zabbix/templates/db/postgresql/
Setting up a template for the Zabbix agent
1. Connect to PostgreSQL.
psql -U postgres
2. Create a read-only user zbx_monitor with access to the PostgreSQL server.
For PostgreSQL version 10 and higher:
CREATE USER zbx_monitor WITH PASSWORD '<ΠΠΠ¨_ΠΠΠ ΠΠΠ¬>' INHERIT; GRANT pg_monitor TO zbx_monitor;
For PostgreSQL version 9.6 and below:
CREATE USER zbx_monitor WITH PASSWORD '<ΠΠΠ¨_ΠΠΠ ΠΠΠ¬>';
GRANT SELECT ON pg_stat_database TO zbx_monitor;
--ΠΠ»Ρ ΡΠ±ΠΎΡΠ° ΠΌΠ΅ΡΡΠΈΠΊ WAL ΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΠ΅Π»Ρ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±ΡΡΡ superuser.
ALTER USER zbx_monitor WITH SUPERUSER;
3. Copy the postgresql/ directory to the /var/lib/zabbix/ directory. If you do not have a zabbix/ directory in /var/lib/, then create it. The postgresql / directory contains the files needed to get metrics from PostgreSQL.
cp -r postgresql/ /var/lib/zabbix/
4. Then copy the template_db_postgresql.conf file to the Zabbix agent configuration directory /etc/zabbix/zabbix_agentd.d/ and restart the Zabbix agent.
* - since I have pgsql version 12, you will have a different path instead of pgsql-12.
If this is not done, then Status: Ping will always be in the Down state.
Adding a template on the Zabbix frontend
I think that those who need to take metrics from PostgreSQL already know how to add templates. Therefore, I will describe the process briefly.
Go to the Zabbix page;
Go to page "Configuration"=>"Hostβ;
Click on the button "Create hostΒ» or select an existing host;
On the page for creating/editing a host, select the tab "templates"and and click on the link"Addβ;
In "Group" from the list, select "Templates / Databases", select the template "Template DB PostgreSQL", press the button"Select"And press the button"Updateβ;
We wait a while and finally, go to "Monitoring"=>"Latest data"=>"HostsΒ» select server with PostgreSQL => click Β«ApplyΒ«.