[ZBX-18938] PostgreSQL monitoring using zabbix-agent2 5.0.8 with pgbouncer does not work Created: 2021 Jan 29 Updated: 2024 Apr 10 Resolved: 2023 Sep 12 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Server (S), Templates (T) |
Affects Version/s: | 5.0.8 |
Fix Version/s: | None |
Type: | Problem report | Priority: | Trivial |
Reporter: | Alexander Yagupov | Assignee: | Denis Rasikhov |
Resolution: | Workaround proposed | Votes: | 1 |
Labels: | None | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified | ||
Environment: |
SLES 15.01 Postgresql 12 |
Attachments: |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Team: |
Description |
Hello. The Postgresql log file contains the following entries: In the log file Zabbix Server: At the same time, the Replication Discovery rule is in the status not supported permanently, with the comment Cannot find the "data" array in the received JSON object. |
Comments |
Comment by Arturs Lontons [ 2021 Feb 01 ] |
Would it be possible to obtain the ouput of zabbix_get on the discovery key?
zabbix_get -s127.0.0.1 -k'pgsql.replication.process.discovery["URI","USER","PASSWORD"]'
And populate the fields within the key accordingly. Please also do the same for the DB discovery key. |
Comment by Alexander Yagupov [ 2021 Feb 01 ] |
For discovery rule zabbix2020:/etc/pgbouncer # zabbix_get -s127.0.0.1 -k'pgsql.db.discovery["/var/run/postgresql/.s.PGSQL.6432","postgres","postgres"]' " : "zabbix"}]} |
Comment by Alexander Yagupov [ 2021 Feb 01 ] |
Hello. I send a screenshot of the execution of commands at your request. I noticed that when running a test of an unsupported data element, any, error (SQLSTATE 26000), then appears, then disappears. But in general, in the interface, the data element remains in the status not supported. 1435:20210201:103326.196 item "Zabbix server:pgsql.replication.lag.sec["{$PG.URI}","{$PG.USER}","{$PG.PASSWORD}"]" became not supported: Cannot fetch data: ERROR: prepared statement "lrupsc_97_0" does not exist (SQLSTATE 26000). zabbix2020:/etc/pgbouncer # zabbix_get -s127.0.0.1 -k'pgsql.autovacuum.count["/var/run/postgresql/.s.PGSQL.6432","postgres","postgres"]' |
Comment by Alexander Yagupov [ 2021 Feb 01 ] |
I found a FAQ on the pgbouncer website http://www.pgbouncer.org/faq.html to fix this PHP/PDO error, but it seems this is not our case. |
Comment by Alexander Yagupov [ 2021 Mar 02 ] |
Hello. Will this problem be solved? |
Comment by Alexander Yagupov [ 2021 Apr 17 ] |
Hello. Thanks. And it turns out that Zabbix-server and zabbix-web work through pgbouncer, but the official template for database monitoring does not. This is probably wrong. |
Comment by Arturs Lontons [ 2021 May 12 ] |
Thanks for the information Alexander! Just to confirm - the discovery rule works as expected without pgbouncer and the issue happens only when pgbouncer is used? |
Comment by Alexander Yagupov [ 2021 May 12 ] |
Hello Arturs! |
Comment by Alexander Yagupov [ 2023 Aug 24 ] |
Hello. |
Comment by Eriks Sneiders [ 2023 Aug 28 ] |
Hi a.yagupov, I tried on Friday to reproduce the issue with some basic pg-bouncer set-up and did not succeed. Maybe you have some steps to reproduce, that would make the attempt easier. Also is it possible for you to share your pg-bouncer configuration, without any sensitive data of course. |
Comment by Alexander Yagupov [ 2023 Aug 28 ] |
Hi Eriks Sneiders, zabbix works great through pgbouncer. The configuration files of pgbouncer and zabbix server are attached. The PostgreSQL by Zabbix agent 2 template does not work via pgbouncer, |
Comment by Denis Rasikhov [ 2023 Sep 06 ] |
Hi a.yagupov. I've managed to reproduce the problem: for that you can restart only the postgresql service during the monitoring and yeah, some items will become unsupported. The problem goes away if after that you also restart either pgbouncer or zabbix-agent2 service. Please note that connecting Zabbix server or frontend to PostgreSQL via PgBouncer is not declared to be officially supported as well as monitoring of PostgreSQL inscances through it and you use this method at your own risk. Also consider using the latest version (link is for Zabbix 6.0) of the template as PostgreSQL templates were updated recently. So the reason behind this behavior is that the plugin uses prepared statements by default. This is not the case with the templates by the classic agent or ODBC, so these work just fine. The PgBouncer FAQ mentions that when you use transaction pooling mode you can't use prepared statements as in that case PgBouncer will have to store them, and it doesn't, so you have to disable them on the client's level. esneiders - we probably could think of implementing the ability to disable these in the plugin config, but maybe the easiest and fastest solution for Alexander would be to use the session pooling mode for the user that is used for monitoring purpose, which will allow to clean old statements in the reset query (with the "server_reset_query = DISCARD ALL" parameter). So you could add a record to the [users] section to the pgbouncer.ini like so (replace zbx_monitor with your user if needed): [users] zbx_monitor = pool_mode=session In that case the template should work correctly. Also, you have this record: [databases] zabbix = Note, that because that's the only connection option specified in your config file, it will only allow connections to the zabbix DB. In this case some metrics for discovered databases will be broken as well, as these require connecting directly to the discovered database. So you must provide connectivity with all DBs for the user that is used for monitoring. Check the template README for instructions about creating a user with proper permissions. |
Comment by Alexander Yagupov [ 2023 Sep 12 ] |
Hello Denis Rasikhov. Your recommendations do not work on Zabbix version 5.0.13. As soon as I set the statement mode in pgbouncer, the web interface becomes unavailable with the errors I wrote about. On Zabbix version 6.0.4, I didn't even try it, because this version works for me to monitor the system, with more than 3000 nodes and I just can't train on it. I will work at my own risk with writing/reading to the database via pgbouncer, via port 6432, which works steadily, gives a big increase in performance, and monitoring the database directly, via port 5432. It is strange that Zabbix does not support the standard products of the software used, in particular Postgresql, which are recommended and supported by developers. By the way, this also applies to the inability to use memcached for PHP-FPM in Zabbix 6.0. I hope in the Zabbix 7.0 version, this will be used for pgbouncer and memcached. (sorry for my English) |
Comment by Denis Rasikhov [ 2023 Sep 12 ] |
That most likely happens because you're changing the pooling mode for all connections, not just for the user that you use for monitoring. In the example above I've only changed the mode for the user zbx_monitor, that template's README suggests you to create. Yeah, if you set mode to session for everyone, Zabbix server connection works fine, but not the frontend. So the setup that I've tested and which works for me on versions since 6.0.21:
There's my configuration files: |
Comment by Alexander Yagupov [ 2023 Sep 12 ] |
Wonderful! it worked in version 5.0.13. I think it will work in version 6.0, just wait for the technological window for maintenance. Thank you. The topic can be closed. |